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 ChauhanPosted Aug 25, 2009, 4:09 AM
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]
Meetu ChoudharyPosted Aug 25, 2009, 3:47 AM
SreekanthPosted Aug 25, 2009, 3:20 AM