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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 multiple inserts

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2004-07-08 : 09:49:21
hello,
how can I do multiple inserts in an sp ?

eg, I am trying to insert name and age of 20 people into one table. staff

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-07-08 : 09:59:28
Insert into staff values(@Name1, @Age1)
Insert into staff values(@Name2, @Age2)
etc.....



Duane.
Go to Top of Page

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-07-08 : 10:00:13
Yes you can.

Series of INSERT...VALUES (probabaly need a loop here) or if you can get them in a set INSERT...SELECT
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2004-07-08 : 11:04:10
INSERT INTO MyTable (Name, Age)
SELECT 'Sam', 18
UNION ALL
SELECT 'Brett', 24
UNION ALL
SELECT 'Tara', 16

et cetera
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-07-09 : 02:46:33
You are being very kind to the other community members Sam

Duane.
Go to Top of Page

sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2004-07-09 : 02:52:24
If u r sending the multiple values thru the front end, then it is better to send an xml to the store procedure rather than calling the sp in a cursor. This will save lot of round trips.
Use openxml method to read the xml. Check BOL for the same.

regards
Sachin
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-07-09 : 08:25:56
quote:
Originally posted by ditch

You are being very kind to the other community members Sam

I think its a bit of old code out of Archive ...

Kristen
Go to Top of Page
   

- Advertisement -