Home Forums SQL Server 2008 T-SQL (SS2K8) how to retrieve the data when a comma separated ids are sent as input parameters RE: how to retrieve the data when a comma separated ids are sent as input parameters

  • CREATE Proc usersbyLocation(@locids varchar(max)=NULL)

    AS

    BEGIN

    Declare @STR varchar(max)

    SET @STR='SELECTUserID,

    UserForename,

    UserSurname,

    LocationName

    fromtUser JOIN

    tLocation on tUser.locationID=tLocation.LocationID

    Where tLocation.LocationID in ('+@locids+')'

    PRINT @locids

    Exec (@str)

    END

    --Test

    --Exec usersbyLocation '1,2,3,4,5,6'