小白求教!!
SQL 里面我想通过@i的变化分别对四组字段赋值,每组有4个字段,请问该怎么写呢?以下的写法提示语法错误!
declare
@i int,
@field1 varchar(100),
@field2 varchar(100),
@field3 varchar(100),
@field4 varchar(100)
set @i=1
while @i<5
begin
set @field1,@field2,@field3,@field4=(case @i
when 1 then fristsl,fristjj,fristsup,fristbuyer
when 2 then secondsl,secondjj,secondsup,secondbuyer
when 3 then thirdsl,thirdjj,thirdsup,thirdbuyer
when 4 then fourthsl,fourthjj,fourthsup,fourthbuyer end)
set @i=@i+1
end
------解决方案--------------------
select case @i when 1 then @field1=fristsl,@field2=fristjj,@field3=fristsup,@field4=fristbuyer
when 2 ......
... end
------解决方案--------------------用if/else来单独赋值吧,case when刚才我试了,不行