当前位置: 代码迷 >> Sql Server >> 在case when中实现变量赋值解决思路
  详细解决方案

在case when中实现变量赋值解决思路

热度:82   发布时间:2016-04-27 18:52:22.0
在case when中实现变量赋值
我想让orderid等于10253时,[email protected],可是要报错:
use   northwind
go
declare   @i   int
set   @i=1;
select   case   orderid   when   10253   then   @[email protected]+1   else   1   end   from   orders
请问用select语句怎么实现orderid等于10253时,[email protected]
谢谢

------解决方案--------------------
select @i = case orderid when 10253 then @i+1 else 1 end from orders

------解决方案--------------------
use northwind
go
declare @i int
set @i = 1
select @i = @i + 1 from orders where orderid = 10253
  相关解决方案