有个语句
CREATE PROC Report3
@Start_date date,
@End_date date
as
select * from a where date between convert(varchar(20),@start_date,120) and convert(varchar(20),@end_date,120)or (@start_date=''and @end_date='')
这样就没错
我现在想在行列转换里面加入这样的限制性条件,就提示数据类型 nvarchar 和 date 在 add 运算符中不兼容
我的代码是这样的
declare @1 varchar(8000)
set @1=‘select ID’
select @1=@1+',max(case A when '''+A+''' then B else 0 end)['+A+']' FROM (select distinct A from tb)a
set @1=@1+' from tb where date between convert(varchar(20),'''+@start_date+''',120) and convert(varchar(20),'''+@end_date+''',120)or (@start_date=''''and @end_date='''') group by ID'
exec(@1)
请问应该怎么修改
------解决思路----------------------
declare @1 varchar(8000)
set @1=‘select ID’
select @1=@1+',max(case A when '''+A+''' then B else 0 end)['+A+']' FROM (select distinct A from tb)a
set @1=@1+' from tb where date between '''+convert(varchar(20),@start_date,120)+''' and '''+convert(varchar(20),@end_date,120)+'''or ('''+convert(varchar(20),@start_date,120)+'''=''''and '''+convert(varchar(20),@end_date,120)+'''='''') group by ID'
PRINT @1
exec(@1)
你写的模糊查询,没感觉有错
试下以上语句
把PRINT @1的结果,贴上来看下~~