在将varchar值'and time between '2012-04-17' and '2012-04-20''转换成数据类型 int 时失败。
我的存储过程里面是这么写的
ALTER PROCEDURE [dbo].[PRO_Priorflow_get]
@strwhere varchar(500),
......
as
begin
select @total=count(1) from PRO_Priorflow where 1=1 + @strwhere
....
end
时由于前台没有选择no的查询,后台查不到数据,求怎么解决的思路
ALTER PROCEDURE [dbo].[PRO_Priorflow_get]
@strwhere varchar(500),
@begintime varchar(500),
@endtime varchar(500),
@no int
......
as
begin
select @total=count(1) from PRO_Priorflow where 1=1 and time between @begintime and @endtime and NO=@no
....
end
declare @total int, @sqls nvarchar(4000)
set @sqls='select @a=count(*) from tableName where 1=1 and time between'+@begintime+'and'+@endtime+'and no='+@no
exec sp_executesql @sqls,N'@a int output',@total output
select @total
@sql = '.....code......'
exec( @sql )
declare @total int, @sqls nvarchar(4000)
set @sqls='select @a=count(*) from tableName where 1=1 and time between'+@begintime+'and'+@endtime+'and no='+ltrim(@no)
exec sp_executesql @sqls,N'@a int output',@total output
select @total