在mysql中使用@variable用作vb.net中的命令

时间:2012-08-14 08:41:00

标签: mysql vb.net

我在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;

1 个答案:

答案 0 :(得分:1)

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

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

然后将其设置为特定值:

SET @prev_rem_balance = 1234;