Query question - multiple values in WHERE

  • Pretty new at this, and I know what I want to do - but can't make it happen:

    I pass a delimited string which I want to split in the stored procedure using a UDF then use each value (of which there may be 1 through 10) as a part of the WHERE to pull a list of names out.  I need these all in the same recordset.

    The SQL below I would think would work, (and it does for a 1 value string) but fails when a string with multiple values are passed.  Any assistance would be wonderful.  Thanks.

    @sText varchar(8000) --comma delimited text of char#'s

    SELECT name

    FROM EMPLOYEE_INFORMATION

    WHERE stop = (SELECT CAST(value as varchar(5)) FROM fn_Split(@sText, ','))

     

  • What does fn_Splt return ? A table variable ? If so, just use it like a table and join to it:

    SELECT name

    FROM EMPLOYEE_INFORMATION As E 

    INNER JOIN dbo.fn_Split(@sText, ',')  As S

      ON (E.stop = CAST(S.value As varchar(5)) )

     

  • I SOOOO should have thought of that - feel kinda dumb.  Works perfectly, thanks much.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply