I have a table in the SQL Server 2005 database that I want to copy 5 columns from one table into another table. I wanted to create a script to do this operation so I can use this on another database that would have different values for these columns.
If I were to use something like this:
DECLARE @.pdtno smallint,
@.publyear smallint,
@.issord int,
@.pdtrnno smallint,
@.layout varchar(60)
code to select the values from the original table and put the column values into variables
code to loop through each record
INSERT INTO layout_temp(pdtno, publyear, issord, pdtrnno, layout)
VALUES (@.pdtno, @.publyear, @.issord, @.pdtrnno, @.layout)
Does this make sense? How would I code the script to go through each record and put the column values from the original table into the variables then insert these into the copy of the original table?
Thanks in advance
? Why not just do: INSERT INTO layout_temp(pdtno, publyear, issord, pdtrnno, layout) SELECT pdtno, publyear, issord, pdtrnno, layout FROM layout-- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <nailers67@.discussions..microsoft.com> wrote in message news:06652218-e226-4a6e-98de-b9046345ef27@.discussions.microsoft.com... I have a table in the SQL Server 2005 database that I want to copy 5 columns from one table into another table. I wanted to create a script to do this operation so I can use this on another database that would have different values for these columns. If I were to use something like this: DECLARE @.pdtno smallint, @.publyear smallint, @.issord int, @.pdtrnno smallint, @.layout varchar(60) code to select the values from the original table and put the column values into variables code to loop through each record INSERT INTO layout_temp(pdtno, publyear, issord, pdtrnno, layout) VALUES (@.pdtno, @.publyear, @.issord, @.pdtrnno, @.layout) Does this make sense? How would I code the script to go through each record and put the column values from the original table into the variables then insert these into the copy of the original table? Thanks in advance|||I believe that was a stupid question on my part. I think I tried to make it too difficult. That worked well. Thank you for your help. I appreciate it.
No comments:
Post a Comment