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 |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2006-05-04 : 09:54:58
|
| Hi,An array of string is being passed to a stored procedure for a usernameso the SP takes the @Username and @stringArrayThe @stringArray is something like "A1,A2,A3,A4,B12"...So the username is to be updated with these values.But at present this username has entries into the database table. I think if first of all the username is deleted from the table, then there will be a new entry for this username again but this time with these multiple values.What is the best way to do a multiple insert for this please?I was thinking may be the answer is sp_xml_preparedocumentWhat do you think?Thanks |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-05-04 : 09:57:52
|
| search for splitText in this forum or in the weblogsthe idea is to split that string into separate values (using the split function) and make multiple inserts for the username specified--------------------keeping it simple... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2006-05-04 : 10:05:28
|
| Yes, I understand about splitting but I am trying to avoid that.The reason is that imagine username "Jo" has several entries already.The new array will replace the existing entries. So I think you should delete the existing entries first and then do the inserts.In fact you need to put them all in a transaction. i.e. delete and then insert. All in one SPDo you agree?Thanks |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-04 : 20:30:47
|
Can you post some sample data and the expected result ? Just to make sure we are in-sync with you KH |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-05-04 : 21:45:05
|
| what you're saying is that you don't really need the existing entries as this will all get replaced by the new values?if yes, then delete and insert will be your approachotherwise, you will need to make comparisons that if those values don't exist then insert otherwise don'tinsert into tableselect value... from dbo.fnsplittext(@array,@delimiter)where id not in (select id from table)--------------------keeping it simple... |
 |
|
|
|
|
|
|
|