日期:2014-05-18  浏览次数:20442 次

sql 消息 245,级别 16,状态 1 错误

消息 245,级别 16,状态 1,第 5 行
在将 varchar 值 '2945,3116,3175,3599,5...


declare @ctt varchar(8000)
select @ctt=isnull(@ctt+',','')+convert(varchar(8),cast(gz_id as varchar(8))) from (select distinct(gz_id) as gz_id from Metro_gzbx_resultinfo) aa
select @ctt

select sum(case when gz_id in (@ctt) then 1 else 0 end) as gg from Metro_gzbx_gz_view


求大神......................

------解决方案--------------------
select count(1) gg from 
 from Metro_gzbx_gz_view
where ','+@ctt+',' like '%,'+ltrim(gz_id)+',%'


------解决方案--------------------
SQL code

gz_id in (@ctt) 改为 CHARINDEX(',' + RTRIM(gz_id) + ',',',' + @ctt) > 0