日期:2014-05-19  浏览次数:20438 次

存储过程的一个问题,拜托高手帮一下
select   count(Top_Job_Name)   from   Job   where   Job_Name= ' "+JobName+ " ' "+strWhere+ "   Order   by   Job_Reldata   desc

把上面这个SQL语句,写进存储过程,该怎么写?
strWhere   代表一个条件语句,比如: "and   Job_ID=4 "。

------解决方案--------------------
create procedure myProc (@JobName varchar(50),@strWhere varchar(1000))
as
select count(Top_Job_Name) from Job where Job_Name=@JobName + @strWhere Order by Job_Reldata desc
------解决方案--------------------
那不能这样写,要用动态sql. 如: declare @sql nvarchar(4000) set @sql = 'select * from Provide where (Province_Name like ' '% '+ @Province_Name+ ......... 然后 exec (@sql)