-1

我在 VB.NET 2008 下使用过这种类型的查询,但每次我运行它时,它总是给我一个致命错误,它告诉我声明我使用的 @variable。下面是示例代码:

select js.year, js.week, js.rem_balance,
       case when js.rem_balance = 0 
                then @prev_rem_balance 
            else js.rem_balance 
       end as rem_balance_zero_or_prev,
       @prev_rem_balance := js.rem_balance
from test_jos_stock js
       inner join (SELECT @prev_rem_balance := 0) as t
order by year,week;
4

1 回答 1

1

您需要在选择语句之前声明参数:

DECLARE @prev_rem_balance INT; --or whatever datatype it is

然后将其设置为特定值:

SET @prev_rem_balance = 1234;
于 2012-08-14T08:45:40.590 回答