Я пытаюсь выбрать некоторые продукты из таблицы продуктов, используя хранимую процедуру в SQL Server 2016, но когда я добавляю несколько продуктов или предложение, возникает синтаксическая ошибка:
Сообщение 102, уровень 15, Состояние 1, Строка 5 Неверный синтаксис около '100'.
Вот строка хранимой процедуры, которая, когда я ее добавляю, выдает ошибку.(без этой строки все нормально):
@StoreId int = null,
//the code is quite verbose and I added storeid variable as a clarification here
//and in the actual code it is defined in the proper line(not here) and the part
//that is creating the error is the below part cause I have tested it and When I
//remove it, it performs ok
IF @ShowUnavailable = 1
set @sql =
'SELECT Distinct P.ProductId, P.BrandId, P.[' + @OrderIndex + '] FROM Products P INNER JOIN ProductStores PS ON P.ProductId = PS.ProductId ' +
'Where PS.StoreId = @StoreId and (PS.Status IN (' + @availabilityStatus + ') or (PS.StoreId != @StoreId and PS.Status IN(0,2))'