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.
| Author |
Topic |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2002-05-03 : 14:56:37
|
| What is the best practice for inserting key/value pairs into a table with a stored proc?Given a table that looks something like thisId uniqueidentifierKey varchar(50)Value varchar(1000)I want to insert data like this:likeDogs YeslikeCats NolikeYaks YesownDog YesownCat NoownYak NoThe way I'm thinking of doing this is calling a stored proc once for each key/value pair. Is that the "best practice" or does someone have a better way? I think I've also seen some people pass in CSV stings and let teh Stored proc parse them out and do the insert. Is that a better solution than calling the stored proc multiple times?TIA!Michael |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-05-03 : 15:17:25
|
| See if this helps:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=12538Personally, I try to avoid repetitive insert statements as much as I can. If building the string, passing it, then parsing it isn't too much of a hassle for you, then I would recommend it. |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2002-05-03 : 20:10:01
|
By the way, nice job working s into your question. |
 |
|
|
jbkayne
Posting Yak Master
100 Posts |
Posted - 2002-05-03 : 23:30:35
|
| If you have SQL2000, you can also pass in a block of XML and use a query using OPENXML to insert the data in bulk. |
 |
|
|
|
|
|