Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi there: I need to select all values from a table "A", and write them to table "B", which already contains some data. Can anybody help me out with a stored procedure. I tried something out and it writes only the last record, instead of all the records.This is what I wrote:Declare @id int,@name varchar (50),@cat varchar (50)select @id =id, @name=name, @cat=cat from Ainsert into B values(@id, @name, @cat)Any help would be very much appreciated.Thanks,- V
eyechart
Master Smack Fu Yak Hacker
3575 Posts
Posted - 2006-02-26 : 13:20:54
You were on the right track with the INSERT INTO syntax. forget about the variables, you don't need them.
INSERT INTO B (col1, col2, col3, etc...)SELECT col1, col2, col3, etc..FROM A
-ec
afrika
Master Smack Fu Yak Hacker
2706 Posts
Posted - 2006-02-26 : 18:02:52
Welcome to SQLTeam, i would advice you to read up the insert syntax in books onlineafrika