Case表达式只能嵌套到10层

szto2003 2009-09-15 10:27:26
我有个sql语句 case when 嵌套超过了10层,提示“Case表达式只能嵌套到10层”,应该怎么解决这个问题,使得sqlserver支持10层以上的嵌套(好像office2007已经支持49层的嵌套了),望高手指点,万分感谢!!
...全文
996 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
walkuere 2011-01-13
  • 打赏
  • 举报
回复
挖坟,我也遇到这个困难了,用union行不行
zhaoweiting0609 2009-09-15
  • 打赏
  • 举报
回复
看看
htl258_Tony 2009-09-15
  • 打赏
  • 举报
回复
贴出来看看代码先
szto2003 2009-09-15
  • 打赏
  • 举报
回复
那怎么写呢,能否给点思路!!
htl258_Tony 2009-09-15
  • 打赏
  • 举报
回复
我以前也有过这么一回,也是改成那样的方式.改的时候是比较麻烦,考虑判断的先后顺序,必要时嵌套一下.
guguda2008 2009-09-15
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 szto2003 的回复:]
这个改起来估计不现实,因为本身就是嵌套判断的,前面条件是后面条件的前提!!
[/Quote]
可不可以用函数代替CASE WHEN
szto2003 2009-09-15
  • 打赏
  • 举报
回复
这个改起来估计不现实,因为本身就是嵌套判断的,前面条件是后面条件的前提!!
szto2003 2009-09-15
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 htl258 的回复:]
SQL codeselectcasewhen1<>1then1elsecasewhen2<>2then1elsecasewhen3<>3then1elsecasewhen4<>4then1elsecasewhen5<>5then1elsecasewhen6<>6then1elsecasewhen7<>7then1elsecasewhen8<>8then1elsecasewhen9<>9then1e¡­
[/Quote]

是这个道理,我看看改成不嵌套的麻不麻烦!!
htl258_Tony 2009-09-15
  • 打赏
  • 举报
回复
估计你用的是14楼的方式,把它转为11楼的方式就可以了.
htl258_Tony 2009-09-15
  • 打赏
  • 举报
回复

select
case
when 1<>1 then 1 else case
when 2<>2 then 1 else case
when 3<>3 then 1 else case
when 4<>4 then 1 else case
when 5<>5 then 1 else case
when 6<>6 then 1 else case
when 7<>7 then 1 else case
when 8<>8 then 1 else case
when 9<>9 then 1 else case
when 10<>10 then 1 else case
when 11<>11 then 1 else case
when 12<>12 then 1 else case
when 13<>13 then 1 else case
when 14<>14 then 1 else case
when 15<>15 then 1 else case
else 2 end end end end end end end end end end end end end end end
end as col
/*
服务器: 消息 125,级别 15,状态 4,行 13
Case 表达式只能嵌套到 10 层。
*/
szto2003 2009-09-15
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 htl258 的回复:]
SQL codeselectcasewhen1<>1then1when2<>2then1when3<>3then1when4<>4then1when5<>5then1when6<>6then1when7<>7then1when8<>8then1when9<>9then1when10<>10then1when11<>11then1when12<>12then1when13<>13then1when1¡­
[/Quote]

我先试一下!!
ADVANTECH_CYZ 2009-09-15
  • 打赏
  • 举报
回复
我就玩过两层,当时很惊奇,case竟然可以嵌套的。
LZ能到10层,太牛了。
htl258_Tony 2009-09-15
  • 打赏
  • 举报
回复

select
case
when 1<>1 then 1
when 2<>2 then 1
when 3<>3 then 1
when 4<>4 then 1
when 5<>5 then 1
when 6<>6 then 1
when 7<>7 then 1
when 8<>8 then 1
when 9<>9 then 1
when 10<>10 then 1
when 11<>11 then 1
when 12<>12 then 1
when 13<>13 then 1
when 14<>14 then 1
when 15<>15 then 1
else 2
end as col
/*
col
-----------
2

(所影响的行数为 1 行)
*/
你用这样的方式.不要嵌套进去
szto2003 2009-09-15
  • 打赏
  • 举报
回复
我的sql语句,试过10层也只要0.1秒都不到!!
soft_wsx 2009-09-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 lxw2100 的回复:]
循环10层的话,这个sql语句肯定有问题,性能方面也有很大影响;建议优化下sql
[/Quote]能不把语句写出来!
szto2003 2009-09-15
  • 打赏
  • 举报
回复
速度无所谓,只要执行成功就行!!
lxw2100 2009-09-15
  • 打赏
  • 举报
回复
循环10层的话,这个sql语句肯定有问题,性能方面也有很大影响;建议优化下sql
szto2003 2009-09-15
  • 打赏
  • 举报
回复
我是一个sql语句做的,因为是一个计算公式,不可以分开搞的!!
ChinaJiaBing 2009-09-15
  • 打赏
  • 举报
回复
路过,
试试判断语句..
--小F-- 2009-09-15
  • 打赏
  • 举报
回复
能写10层已经很牛了 试问能运行动吗?
加载更多回复(3)

34,589

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧