I have a large T-SQL query (I only put a part here because I very sure the rest is working nice):
 WHERE /*
                ******* missing filter *******
                this line should filter the risks by @LoggedInPersonID via role 
                ******************************
          AND */(@PropertyID IS NULL OR p.PropertyID = @PropertyID)
          AND (@PCodePattern IS NULL OR p.PCode LIKE @PCodePattern)
          AND (@ZipCodeIDS IS NULL 
                 OR p.ZipCodeID IN (@ZipCodeIDS))
You notice that @ZipCodeIDS is a list... Well, I populate this from code with some ids. When @ZipCodeIDS contains a SINGLE id it works perfectly but if I try to send multiple ids (eg: "14,15") it gives me error....
Do you have any clue?
Ps: Of course I made @ZIpCodeIDS varchar because we do not have array in T-SQL...
UPDATE: If I directly hardcode in the query: IN (14,11) it perfectly works... so somehow I do not correctly send this parameter from my code for multiple values I think it does not see "," as a separator...
UPDATE 2: Tried to split the lists and put the ids into a table... When zipCodeIDS has only one id the query works perfectly. For multiple ones, not... Do you see something strange on ELSE?
    IF @ZipCodeIDS IS NOT NULL
BEGIN
    IF CHARINDEX(',', @ZipCodeIDS) = 0
    BEGIN
        insert @listofIDS values(@ZipCodeIDS)
    END
    ELSE
    BEGIN
        WHILE CHARINDEX(',', @ZipCodeIDS) != 0
        BEGIN
            insert @listofIDS values(Left(@ZipCodeIDS, PatIndex(',', @ZipCodeIDS) - 1))
            SET @ZipCodeIDS = SUBSTRING(@ZipCodeIDS, CHARINDEX(',',@ZipCodeIDS)+1, LEN(@ZipCodeIDS) - CHARINDEX(',',@ZipCodeIDS))
        END
    END
END
 
     
     
     
     
     
    