我这个语句到底错在那里啊?求助!!!

xmily2005 2012-03-21 10:14:20
declare @Result varchar(200)
set @Result=''
select
case
when route_spot is not null then @Result=@Result+route_spot+',' end
end
from
tlinerouteinfo
where
route_lineid=10

select @Result



————————————————————
消息 102,级别 15,状态 1,第 17 行
'=' 附近有语法错误。
...全文
54 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmily2005 2012-03-21
  • 打赏
  • 举报
回复
非常感谢 TravyLee及Beirut ,看到TravyLee的回复时,我发现我真笨,呵呵,的确是可以在WHERE中判断的,脑子没转过弯来。当然通过beirut的回复让我了解了正确的使用语法,呵呵。感觉两位。也感谢zhaowenzhong,虽然你的回复测试了但还是有错误。呵呵。结贴
xmily2005 2012-03-21
  • 打赏
  • 举报
回复
谢谢,各位的回复,我试一下先O。
黄_瓜 2012-03-21
  • 打赏
  • 举报
回复
case when 语法不是这样用的


select  @Result= @Result+
case
when route_spot is not null then route_spot+','
else ''
end
from


或者用一楼的
xmily2005 2012-03-21
  • 打赏
  • 举报
回复
谢谢各位的回复,我试一下先O
Felixzhaowenzhong 2012-03-21
  • 打赏
  • 举报
回复

少 ELSE
select case when then else end --语法格式
  • 打赏
  • 举报
回复


declare @Result varchar(200)
set @Result=''
select
@Result=@Result+route_spot+',' from tlinerouteinfo
where
route_lineid=10 and route_spot is not null

select @Result

34,590

社区成员

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

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