• Why not pass in XML into the SP? I.e.

    @BrandId_List XML --e.g. <Brands><id>1</id><id>2</id></Brands>

    And then your query could look like this:

    SELECT *

    FROM

    Sales s

    INNER JOINProducts p on s.customerId = p.customerId

    INNER JOINBrands b on p.BrandId = b.BrandId

    WHERE

    tb.BrandId IN (SELECT Brands.ID.value('.','INT')

    FROM @BrandId_List.nodes('/Brands/id') AS Brands(ID))

    OR @BrandID_List IS NULL

    By passing NULL for the parameter would still achieve the same result; you would just have to build the XML before passing into the SP. Also worth noting that you can apply an XML namespace here to make sure your XML markup conforms to a set standard.