消息 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)