declare @i int
case
when @i=1 then select * from a when @i=2 then select * from b
when @i=1 then select * from a
when @i=2 then select * from b
end
这样的功能怎么实现
我上面的语句是错误的
你这样的需求要使用到动态语句,如下:
declare @sql varchar(1000)
set @sql = case when @i = 1 then 'select * from a'
when @i = 2 then 'select * from b'
when @i=1 then select * from a when @i=2 then select * from b end 这样的功能怎么实现 我上面的语句是错误的
或
if @i=1
select * from a
else if @i=2
select * from b
update
ta
case ta.a
when 1 then set ta.b = ta.b + 1 when 2 then set ta.c = ta.c + 1 when 3 then set ta.d = ta.d + 1
when 1 then set ta.b = ta.b + 1
when 2 then set ta.c = ta.c + 1
when 3 then set ta.d = ta.d + 1
from
根据条件修改相同字段的值没问题了。
但这种情况是根据条件修改不同的字段的值。像这种情况是不是得fetch next来做。
一条语句能不能实现?