-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Sam786786
Message 1 in Discussion






Hi Balaji


 


 


Function below which will accept comma delimited string and
will return each value as a seprate row, further the results can be used.


 


1)         select * from dbo.FN_SPLIT('2,3,4,5',',')


            here first parameter for stored procedure is
string and second parameter is delimiter by which values are separated.


2)         will return


            2


            3


            4


            5


 


you can use this function in your stored procedure as


 


select UserID,MasterID
from tableA Where MasterID in (select col_1 from dbo.FN_SPLIT('2,3,4,5',','))


 


 


 


create      FUNCTION dbo.FN_SPLIT ( 


 @src_str  AS  VARCHAR(5000),


 @row_delim  AS  VARCHAR(100)


 )


RETURNS @TEMP1 TABLE


   (


 COL_1 VARCHAR(2000)


   )


BEGIN


 DECLARE @temp_str  AS VARCHAR(5000)


 DECLARE @start_pos  AS INT --Start position


 DECLARE @end_pos  AS INT --End position


 DECLARE @row_delim_len  AS INT


-- DECLARE @col_delim_len  AS INT


 DECLARE @len   AS INT


 


 


 SELECT @end_pos  = CHARINDEX(@row_delim, @src_str)


 SELECT @start_pos = 1


 SELECT @row_delim_len = LEN(@row_delim)


 


 WHILE @end_pos > 0


 BEGIN


  SELECT @len = @end_pos - @start_pos


  IF @len > 0 


   SELECT @temp_str = SUBSTRING ( @src_str , @start_pos ,@len 
) 


  SELECT @start_pos = @end_pos + @row_delim_len


  SELECT @end_pos  = CHARINDEX(@row_delim, @src_str,@start_pos)


  INSERT INTO @TEMP1 SELECT ISNULL(@temp_str,'')


 END


  SELECT @len = LEN(@src_str) - @start_pos + @row_delim_len


  IF @len > 0 


  BEGIN


   SELECT @temp_str = SUBSTRING ( @src_str , @start_pos ,@len 
) 


   INSERT INTO @TEMP1 SELECT ISNULL(@temp_str,'')


  END


 RETURN


 


 


 


Hopes it will help


Mohammad 


 





-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to