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 insert

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 username
so the SP takes the @Username and @stringArray
The @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_preparedocument
What 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 weblogs

the idea is to split that string into separate values (using the split function) and make multiple inserts for the username specified

--------------------
keeping it simple...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-04 : 10:01:07
Also refer to this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-04 : 10:01:34
Refer this
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 SP
Do you agree?

Thanks
Go to Top of Page

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

Go to Top of Page

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 approach
otherwise, you will need to make comparisons that if those values don't exist then insert otherwise don't

insert into table
select value... from dbo.fnsplittext(@array,@delimiter)
where id not in (select id from table)



--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -