Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 generate column list names.

Author  Topic 

Cass
Starting Member

9 Posts

Posted - 2008-07-10 : 11:53:12
Hei!
How to generate column list for this code. Both table include identity column

SET IDENTITY_INSERT Table1 ON
INSERT INTO Table2
SELECT *
FROM Table1
WHERE ID=5
SET IDENTITY_INSERT Table1 OFF

I don't want to do handwrite so much if there are 20 columns

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-10 : 11:56:35
Right click on table is Query analyzer and select script insert to clipboard, for table2
and script select for table 1


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

Cass
Starting Member

9 Posts

Posted - 2008-07-10 : 12:10:56
Thanx, it good tip but not so good solution for me.
In future if tables are modified then must procedure also modify but i try to avoid this.

Something like universal INSERT INTO procedure where columns list is generated on the fly.
Go to Top of Page
   

- Advertisement -