Jump to content

Recommended Posts

I think I'm not really in the right state of mind right now to do this, I seem to remember a very neat shortcut to populate an identical set of columns in a table with data from another table.

 

A bit of background, I have a table called domains, with fields called NS1, NS2, NS3...NS13.  I am writing a page to turn the domains off when they're expired, and I want to hold this data in a new table called expired_domains for safekeeping when the time comes to restore it.  It has identical fields, NS1, NS2, NS3...NS13.

 

It would be something like an INSERT SELECT right?

INSERT INTO tbl_name (`col`, `col2`) SELECT `col`, `col2` FROM tabl_name WHERE x=x;

 

Should work. If the tbl_name columns matches the ones in tabl_name you can omit the (`col`..) portion and change the select to * instead of defining each column.

$q_copyns = "INSERT INTO brat_exp_ns ('domain_name','NS1','NS2','NS3','NS4','NS5','NS6','NS7','NS8','NS9','NS10','NS11','NS12','NS13') SELECT 'domain_name','NS1','NS2','NS3','NS4','NS5','NS6','NS7','NS8','NS9','NS10','NS11','NS12','NS13' FROM Domain WHERE domain_name='$turnoff[$i]'";

 

Throws an SQL error regarding an invalid object named brat_exp_ns.  Removing the quotes from the first set of columns inserts static data with those values (domain_name gets domain_name, etc).  Backticks as you have displayed don't work with MSSQL.

 

EDIT:  Got it, you actually need to have no quotes at all.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.