Groups | Blog | Home
all groups > sql server programming > may 2004 >

sql server programming : Splitting the String


Ramnadh
5/3/2004 11:51:03 PM
Hi
I have the problem in splitting the string in T-Sql

For example the string is like $EmpId = 1$; $EmpMgr=2323$;$DeptNo=20$

I have to get the EmpId , EmpMgr and DeptNo from the string i.e 1,2323 and 20 and use those values in th

query. can anyone help me how can the splitting of the string is done

Regards
Ramnadh
5/4/2004 2:31:05 AM
Thanx for your reply

But when i am executing the sample query send by you. When cross joinining the Table SysObjects it is taking lot o

Ramnadh
5/4/2004 2:56:03 AM
Uri Dimant
5/4/2004 10:32:23 AM
hI
This example has written by Anith
Here is given an idea so you have to modify it for your needs

SELECT IDENTITY(INT) "n" INTO Numbers
FROM sysobjects s1
CROSS JOIN sysobjects s2
GO
DECLARE @Ids VARCHAR(200)
SET @Ids = '5,33,229,1,22'
SELECT SUBSTRING(@Ids, n, CHARINDEX(',', @Ids + ',', n) - n)
from numbers where substring(','+@Ids,n,1)=','
AND n < LEN(@Ids) + 1
drop table Numbers


[quoted text, click to view]

Uri Dimant
5/4/2004 12:34:50 PM
Ramnadh
The idea was to get a table which contains a sequential numbers.
Just remove CROSS JOIN statement and see if it helps.



[quoted text, click to view]

AddThis Social Bookmark Button