参数值的问题
在VS上面开发报表,以下是查询设计器中的语句:
select Cdate, Ctime, Jdate, Jtime, hs, ccbh_1, bm,
sbmc_1, sbbh_1, cpgg_1, Sdate,Stime, Edate, Etime, wxjl_1, shyy, wxry_1,Status, desc_1 as id_11,ma_time as id_12
from sh_device_report
where 1=1
and (Cdate>= convert(varchar(10),@Sdate,121) AND Cdate<= convert(varchar(10),@Edate,121))
and (Jdate >= convert(varchar(10),@Sdate1,121) AND Jdate<= convert(varchar(10),@Edate2,121))
and (bm in (@bm))
and (shyy IN (@shyy))
and (Status IN (@Status))
and (desc_1 LIKE (@ID_11) or desc_1 is NULL)
and (sbmc_1 IN (@sbmc_1))
AND (sbbh_1 IN (@sbbh_1) OR sbbh_1 LIKE @godD1)
AND (ccbh_1 IN (@ccbh_1) OR ccbh_1 LIKE @godD2)
现在有个问题没法处理:
@Sdate、@Edate、@Sdate1、@Edate2 字符型的。
这两组日期条件可选可不选,请教下上面语句该如何修改。
and (Cdate>= convert(varchar(10),@Sdate,121) AND Cdate<= convert(varchar(10),@Edate,121))
and (Jdate >= convert(varchar(10),@Sdate1,121) AND Jdate<= convert(varchar(10),@Edate2,121))
这段就有问题。
现在是如果这2组日期条件放空会导致没有数据。
------解决方案--------------------
exec('select * from tb where sbbh_1 in ('+@sbbh_1+')')