Создайте нижеприведенную функцию.
СОЗДАЙТЕ ФУНКЦИЮ [dbo]. [Split] (@InputString nvarchar (max), @Delimiter nvarchar (50))
ВОЗВРАТЫВАНИЕ @Items TABLE (Элементnvarchar (max))
КАК НАЧАТЬ, ЕСЛИ @Delimiter = '' НАЧАТЬ НАБОР @Delimiter = ',' SET @InputString = REPLACE (@InputString, '', @Delimiter) END
IF (@Delimiter IS NULL OR @Delimiter = '')
SET @Delimiter = ','
DECLARE @Item nvarchar(max)
DECLARE @ItemList nvarchar(max)
DECLARE @DelimIndex INT
SET @ItemList = @InputString
SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
WHILE (@DelimIndex != 0)
BEGIN
SET @Item = SUBSTRING(@ItemList, 0, @DelimIndex)
INSERT INTO @Items VALUES (@Item)
SET @ItemList = SUBSTRING(@ItemList, @DelimIndex+LEN(@Delimiter), LEN(@ItemList)-@DelimIndex)
SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
END -- End WHILE
IF @Item IS NOT NULL -- At least one delimiter was encountered in @InputString
BEGIN
SET @Item = @ItemList
INSERT INTO @Items VALUES (@Item)
END
-- No delimiters were encountered in @InputString, so just return @InputString
ELSE INSERT INTO @Items VALUES (@InputString)
RETURN
END
использовать этот оператор выбора в хранимой процедуре
Выбрать * из TableName, где AND T.OrderType IN (select * from dbo.Split (@OrderType, ','))