日期:2014-05-18 浏览次数:20567 次
where 和 @str 之间没空格 你直接print @sql出来看看就知道了
------解决方案--------------------
CREATE PROCEDURE NewsPaperReport8(@str nvarchar(2000)) AS declare @sql nvarchar(4000), set @sql='SELECT TYPENAME,adname,CheckName,CheckEnterprise,IsSex,channelname,COUNT(ADNAME) AS BCCS FROM( SELECT (case typename when ''处方药'' then ''药品'' when ''非处方药'' then ''药品''else typename end) as typename, adname,CheckName,CheckEnterprise,IsSex,channelname FROM t_result WHERE '+@str+' AND (IsSex=''1''))tt GROUP BY ADNAME,TYPENAME,CheckName,CheckEnterprise,IsSex,channelname ORDER BY (case TYPENAME when ''药品'' then ''1'' when ''保健食品'' then''2'' when ''医疗器械'' then ''3'' when''其他'' then ''4'' end),ADNAME' print @sql exec sp_executesql @sql GO exec NewsPaperReport7 'mediatype=''2'' and checkenterprise like ''合肥%'''
------解决方案--------------------
你qq多少,我帮你看看。不一定非得拼字符串