为什么我得到错误?在synapse数据仓库工作
Msg 137, Level 15, State 2, Line 1
必须声明标量变量&;@p_src_id&;
我声明了它。我对它进行了修补,如果我将GETDATE()
插入到变量的查询中,它将工作,但它不会与变量一起工作。我有能力变通;我只是想了解问题所在。
DECLARE @p_src_id INT = 4389,
@v_ts DATETIME2(6) = GETDATE(),
@v_rnk INT;
SELECT @v_rnk = CASE WHEN @v_ts BETWEEN dt.eff_dt AND dt.exp_dt
THEN 1
ELSE 0
END
FROM (SELECT MIN(eff_dt) AS eff_dt,
MIN(exp_dt) AS exp_dt
FROM dbo.my_dates
WHERE src_id = @p_src_id) AS dt;
----THIS WORKS!!
--SELECT @v_rnk = CASE WHEN GETDATE() BETWEEN dt.eff_dt AND dt.exp_dt
-- THEN 1
-- ELSE 0
-- END
--FROM (SELECT MIN(eff_dt) AS eff_dt,
-- MIN(exp_dt) AS exp_dt
-- FROM dbo.my_dates
-- WHERE src_id = @p_src_id) AS dt;
SELECT @v_rnk;
去掉第3行INT
后面的分号