'Variable scope in Synapse data warehouse - Must declare the scalar variable (very clearly declared)

Why am I getting the error? Working in synapse data warehouse.

Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@p_src_id"

I declared it. I tinkered with it and it will work if I plug GETDATE() into the query in place of the variable, but it will not work with the variable. I am capable of a work-around; I just want to understand the problem.

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;


Solution 1:[1]

Remove the semi-colon on line 3 after INT

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dani U