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
 Re: Stored Procedure Help

Author  Topic 

vishnun
Starting Member

1 Post

Posted - 2006-02-26 : 13:15:51
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 A

insert 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

Go to Top of Page

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 online

afrika
Go to Top of Page
   

- Advertisement -