加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLServer中Case when的一个意外问题

发布时间:2020-12-12 15:54:15 所属栏目:MsSql教程 来源:网络整理
导读:在论坛回答问题时,发现测试脚本会出现如下问题,百思不得其解。 set ?nocount? on create ? table ?test(a? varchar ( 10 )) insert into ?test? select ? ' a ' b declare @str1 8000 ) @str2 @str1 = '' @str2 = + a? from order by ?a print -- 返回ab ?
在论坛回答问题时,发现测试脚本会出现如下问题,百思不得其解。

set ?nocount? on

create ? table ?test(a? varchar ( 10 ))

insert into ?test? select ? ' a ' b


declare @str1 8000 )

@str2 @str1 = '' @str2 = + a? from order by ?a

print -- 返回ab

?test?

?

case ?a???? when then ? 1

????????
2 else 99 end 返回b drop ?test

off 上面的@str2会丢失前面的所有记录,只保留order by的最后一条-_-||

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读