日期:2014-05-18 浏览次数:20472 次
CREATE PROCEDURE [dbo].[Find_] @daeStart smalldatetime , @daeEnd smalldatetime , @strBmph varchar(20) , @strField varchar(5) , @strText varchar(20) as declare @i int , @strSql varchar(100) set @i = 1 if @strBmph <> '' set @strSql = ' and bmph = ' + @strBmph if @strField <> '' and @strText <> '' set @strSql = @strSql + ' and ' + @strField + ' = ' + @strText begin /*以下语法错误,请大家赐教。*/ exec('select * from aaa where bDel = 0 '+ @strSql ) end go exec [Find_] '2011-6-10','2011-6-30' , '人事部' , '' ,'' go drop procedure find_
------解决方案--------------------
CREATE PROCEDURE [dbo].[Find_]
@daeStart smalldatetime ,
@daeEnd smalldatetime ,
@strBmph varchar(20) ,
@strField varchar(5) ,
@strText varchar(20)
as
declare @i int , @strSql varchar(100)
set @i = 1
set @strSql='select * from aaa where bDel = 0 '
if @strBmph <> '' set @strSql = ' and bmph = ' + @strBmph
if @strField <> '' and @strText <> '' set @strSql = @strSql + ' and ' + @strField + ' = ' + @strText
print (@strSql)
exec (@strSql)
------解决方案--------------------