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

报错:服务器: 消息 170,级别 15,状态 1,行 4
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'

exec sp_executesql @sql
GO

exec NewsPaperReport7 'mediatype="2" and checkenterprise like "合肥%"'

报错:服务器: 消息 170,级别 15,状态 1,行 4
第 4 行: '=' 附近有语法错误。

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

where 和 @str 之间没空格

你直接print @sql出来看看就知道了

------解决方案--------------------
SQL code
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多少,我帮你看看。不一定非得拼字符串