bluesoul Posted January 5, 2009 Share Posted January 5, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/139574-mssql-populate-a-row-with-data-from-another-table/ Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/139574-mssql-populate-a-row-with-data-from-another-table/#findComment-730162 Share on other sites More sharing options...
bluesoul Posted January 5, 2009 Author Share Posted January 5, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/139574-mssql-populate-a-row-with-data-from-another-table/#findComment-730283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.