User Id :    Password :      New Member   Forgot Password  
Sql Server function to convert comma separated value into tabular format
Description Some times when writing sql query we have comma separated values and we want to convert it into tabular format so that we can apply in clause easily. So for that purpose I am giving a function that can perform this task very easily. You need to pass only the comma separated values as argument and it return the tabular format.   No. of Views     2468
  Rating     5
Author Sumit Gupta   Posted On     11 Jul 2011
Tags SQL SERVER,General    

Sample Code   Download Code

Create Function fn_GetSeprateValues(@Ids varchar(8000))
returns @Table Table(Id varchar(100))

Declare @ind int
Declare @Start int

Set @Ids=@Ids+','
Set @Start=1

Set @ind =charindex(',',@Ids)
        Declare @SubId varchar(100)
        Set @SubId=Substring(@Ids,@Start,(@ind-1))
        if(@SubId<>'' and @SubId Is Not Null)
            insert into @Table(Id) values(@SubId)
        Set @Ids =Substring(@Ids,@ind+1,Len(@Ids))
        SET @ind = charindex(',',@Ids ) 




I hope it make sense..

About Author

About Author I am Sumit Gupta working in 3 Pillar Global Pvt. Ltd as Module Lead. I have 7+ year of experience in .Net technologies. I love to explore new technologies and write technical article. Sumit Gupta
No Photo
Country India
Company 3 Pillar Global Pvt. Ltd.
Home Page

Rate this article

Rating options from poor, fair, good, very good to excelent.  


Posted By Annonymous on 02 Sep 2011 at 10:34 PM
Hey, good to find someone who aegers with me. GMTA.
Write your comment here.
Verification Code