我正在尝试将变量分配给存储过程中的case语句。
这是我的代码:
CREATE Procedure [dbo].[myProcedure]
(
@StartDate DATETIME = NULL,
@EndDate DATETIME = NULL,
)
AS
DECLARE @Type varchar
SET @Type = NULL
BEGIN
SELECT DISTINCT
@Type = CASE
WHEN myTable.myVariable = '1'
THEN 'No'
END AS 'Test'
FROM myTable
WHERE myTable.myDate BETWEEN @StartDate AND @EndDate
END
我收到的错误是myTable.myVariable
多部分标识符无法绑定....我可能这样做完全错了虽然...我只是想把我的case语句分配给变量...
答案 0 :(得分:0)
这对我有用:
DECLARE @I1 BIGINT
SET @I1 = (
SELECT Top 1 CASE WHEN LIST_PRICE=75 THEN [EAN]
ELSE 0 END SPECIAL
FROM dbo.x1)
SELECT @I1