VB的select case语句替换成SQL Server的简单case函数,怎么写?
VB:
select case a+b '这里a+b实际是一个比较复杂的计算式。
case is < 10
debug.print "<10"
case is <20
depub.print "10~20"
case else
debug.print "more then 20"
end select
换成SQL Server:
select
case @a+@b when is < 10 --这里 is <10 在SQL Server里怎么写?
then '<10' --因为@a+@b实际很复杂,不想多次计算。
when is <20
then '10~20'
else 'more then 20'
end
当然可以写成
case when @a+@b<10 then ...
else when @a+@b<20
then ...
这样的形式,不过多次计算@a+@b,感觉效率太低。
谢谢回复。
...全文
请发表友善的回复…
发表回复
tinghuyang 2004-03-29
- 打赏
- 举报
up
victorycyz 2004-03-29
- 打赏
- 举报
算了,结贴。
zdk210 2004-03-29
- 打赏
- 举报
请问
case
when @a+@b < 10 then '10'
when (@a+@b < 20) and (@a+@b > 10) then '10-20'
else 'more then 20' end as 'test'
这样子会计算多次吗?为什么
case
when @a+@b < 10 then '10'
when (@a+@b < 20) and (@a+@b > 10) then '10-20'
else 'more then 20' end as 'test'
这样子会计算多次吗?为什么
leeboyan 2004-03-29
- 打赏
- 举报
平时抢楼的大侠呢?
leeboyan 2004-03-29
- 打赏
- 举报
顶
victorycyz 2004-03-29
- 打赏
- 举报
咦,是不能这样写还是分太少?
高手给个话呀。
leeboyan 2004-03-29
- 打赏
- 举报
学