Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Below is the example Once data comes in to table then you can easily bind data in to list box.</p> <p><strong>STEP 1</strong></p> <p>Execute the following procedure in your Sql Server window.</p> <p>The fn_CommaSeparatedStringToTable function accepts comma separated string and a value('Y' or 'N') to include NULL and EMPTY strings in the result set</p> <pre><code>ALTER FUNCTION [dbo].[fn_CommaSeparatedStringToTable] ( @CommaSeparatedValues VARCHAR(MAX), @IncludeEmptyStrings CHAR(1) ) RETURNS @Item TABLE ( RowId int IDENTITY(1, 1) NOT NULL, Value VARCHAR(200) ) AS BEGIN DECLARE @IndefOfComma int, @Value VARCHAR(200),@StartPos bigint,@EndPos bigint,@LengthOfString int, @ReachedEnd Char(1) SET @StartPos=1 SET @EndPos=0 SET @LengthOfString=LEN(@CommaSeparatedValues) SET @ReachedEnd='N' WHILE @ReachedEnd&lt;&gt;'Y' BEGIN SET @EndPos=CHARINDEX(',',@CommaSeparatedValues,@StartPos) IF @EndPos&gt;0 BEGIN SET @Value = SUBSTRING(@CommaSeparatedValues, @StartPos,@EndPos- @StartPos) SET @StartPos=@EndPos+1 END ELSE BEGIN SEt @ReachedEnd='Y' SET @Value = SUBSTRING(@CommaSeparatedValues, @StartPos,@LengthOfString-(@StartPos-1)) END IF(@Value&lt;&gt;'' OR @IncludeEmptyStrings='Y') INSERT INTO @Item(Value) VALUES(@Value) END RETURN END </code></pre> <p><strong>STEP 2</strong></p> <p>To access the function, use the following query </p> <pre><code> Include Empty or Null String in the result SELECT * FROM [dbo].[fn_CommaSeparatedStringToTable] ('ALICE,BRAD,JOHN,JOE,MIC,SCAIF,JEMY, ,','Y') Do not include Empty or Null String in the result SELECT * FROM [dbo].[fn_CommaSeparatedStringToTable] ('ALICE,BRAD,JOHN,JOE,MIC,SCAIF,JEMY, ,','N') </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload