当前位置: 代码迷 >> Sql Server >> 消息 156,级别 15,状态 1,第 1 行 关键字 'case' 附近有语法异常
  详细解决方案

消息 156,级别 15,状态 1,第 1 行 关键字 'case' 附近有语法异常

热度:605   发布时间:2016-04-24 21:44:33.0
消息 156,级别 15,状态 1,第 1 行 关键字 'case' 附近有语法错误。
--try:
 declare @sql1 varchar(8000)
 set @sql1=''
 select @sql1=@sql1+'max(case when PicTitle='''+PicTitle+''' then PicUrl else 0 end) as ['+PicTitle+']' from Attachment group by PicTitle
 set @sql1='select'+@sql1+' from Attachment group by PicTitle'
 exec(@sql1)

------解决方案--------------------
exec前
print @sql1出来看看
------解决方案--------------------
declare @sql1 varchar(8000)
 set @sql1=''
 select @sql1=@sql1+'max(case when PicTitle='''+@PicTitle+''' then PicUrl else 0 end) as ['+PicTitle+']' from Attachment group by PicTitle
 set @sql1='select'+@sql1+' from Attachment group by PicTitle'
 exec(@sql1) 
  相关解决方案