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 |
reogeo
Starting Member
2 Posts |
Posted - 2012-07-03 : 07:56:55
|
Hi all,This is the format of the string i am passing to the stored procedure and i want to split the string with ; as the delimiter and insert it into a table String Format ;Alfa Romeo;Opel;Suzuki;Tiger the table format after insertion is asbelowID UserID Make1 2 Alfa Romeo2 2 Opel3 2 Suzuki4 2 TigerCan i do the spliting and insertion in the same stored procedure...Please help me out in this issue..Thanks in Advance.. |
|
rocknpop
Posting Yak Master
201 Posts |
Posted - 2012-07-03 : 11:30:16
|
try this:DECLARE @str VARCHAR(100) = ';Alfa Romeo;Opel;Suzuki;Tiger', @xml xmlSET @str = SUBSTRING(@str,2,LEN(@str))SET @str = '<root><row>' + REPLACE(@str,';','</row><row>') + '</row></root>'SET @xml = CAST(@str AS XML)SELECT tab.col.value ('.','varchar(50)')FROM @xml.nodes('/root/row') tab(col)--------------------Rock n Roll with SQL |
 |
|
|
|
|