I have a simple stored procedure like this:
[dbo].[getStatusList]
@Extended NVARCHAR(255) = 'Project Status',
@Exclude NVARCHAR(255) = '',
@All BIT = 0
AS
SET NOCOUNT ON
IF (@All = 0)
BEGIN
SELECT
[GeneralKey],
[Label]
FROM
[General]
WHERE
[Extended] = @Extended
AND [Label] <> @Exclude
ORDER BY
[OrderID];
END
ELSE
BEGIN
IF (@All = 1)
BEGIN
SELECT
0 AS [GeneralKey],
'Any' AS [Label],
0 AS [OrderID]
UNION ALL
SELECT
[GeneralKey],
[Label],
[OrderID]
FROM
[General]
WHERE
[Extended] = @Extended
AND [Label] <> @Exclude
ORDER BY
[OrderID];
END
END
That I want to do is exec this stored procedure sending twice @Extended
parameter like:
exec getStatusList @Extended = 'title1' AND @Extended = 'title2'
It is not possible to do something like this on exec
? To only way to solve this is to add another parameter to stored procedure?
Update
As comments below mentioned, I tried this:
CREATE OR ALTER PROCEDURE usp_Get_StatusListByDesignType
-- Add the parameters for the stored procedure here
@Extended NVARCHAR(MAX),
@Exclude NVARCHAR(255) = '',
@All BIT = 0
AS
SET NOCOUNT ON
IF (@All = 0)
BEGIN
DECLARE @Parameter1 VARCHAR(50)
DECLARE @Parameter2 VARCHAR(50)
;WITH CTE AS
(
SELECT
*,
ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) rn
FROM
STRING_SPLIT (@Extended,',')
)
SELECT
@Parameter1 = MAX(CASE WHEN rn = 1 THEN VALUE END),
@Parameter2 = MAX(CASE WHEN rn = 2 THEN VALUE END)
FROM
CTE
SELECT
[GeneralKey], [Label]
FROM
[General]
WHERE
[Extended] IN (SELECT @Parameter1, @Parameter2)
AND [Label] <> @Exclude
ORDER BY
[OrderID];
END
ELSE
BEGIN
IF (@All = 1)
BEGIN
SELECT
0 AS [GeneralKey],
'Any' AS [Label],
0 AS [OrderID]
UNION ALL
SELECT
[GeneralKey],
[Label],
[OrderID]
FROM
[General]
WHERE
[Extended] IN (SELECT @Parameter1, @Parameter2)
AND [Label] <> @Exclude
ORDER BY
[OrderID];
END
RETURN;
But I get this error:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.