If i give a value like this
'11,12|13,14|15,16'
I want to remove that ',' and '|' and i need my output as follows:
id value1 value2
1 11 12
2 13 14
3 15 16
I want to achieve this by inserting values in temporary table and by using charindex in sql server
thanks in advance
Loading

Sanjay Chauhan55 reputationPosted Aug 25, 2009, 12:09 AM EDT
Try this:
CREATE TABLE #TempKeywords(
Value1 int,
Value2 int )
DECLARE @Keywords VARCHAR(50)
SET @Keywords='11,12|13,14|15,16'
While (Charindex('|',@Keywords)>0)
Begin
Insert Into #TempKeywords ([Value1],[Value2]) VALUES( ltrim(rtrim(Substring(@Keywords,1,Charindex(',',@Keywords)-1))), ltrim(rtrim(Substring(@Keywords,4,Charindex(',',@Keywords)-1))))
Set @Keywords = Substring(@Keywords,Charindex('|',@Keywords)+1,len(@Keywords))
End
Insert Into #TempKeywords ([Value1],[Value2]) VALUES( ltrim(rtrim(Substring(@Keywords,1,Charindex(',',@Keywords)-1))), ltrim(rtrim(Substring(@Keywords,4,Charindex(',',@Keywords)-1))))
SELECT * FROM [#TempKeywords]
Sreekanth199 reputationPosted Aug 24, 2009, 11:20 PM EDT
Meetu ChoudharyRank #1,984 · 735 reputationPosted Aug 24, 2009, 11:47 PM EDT