select
a.zyq,a.qk,e.jh,(isnull(e.c_cc,'')+isnull(e.c_cs,'')+isnull(e.c_bs,'')+isnull(e.c_bj,'')) as "内容",
datediff(dd,dateadd(dd,-5,e.rq),b.rq) as "num1",
b.rq as "qrq",b.cc as "qcc",b.cs as "qcs",b.bj as "qbj",b.bs as "qbs",b.scsj as "qscsj",
b.rcyl1 as "qrcyl1",b.rcyl as "qrcyl",b.hs as "qhs",b.dym_new as "qdym_new",b.bx as "qbx",b.bz as "qbz",
e.rq ,convert(varchar(10),e.rq,120) as "调参日期1"
from tjc01 a,tba01 b,tba01 e
where a.jb=1 and e.dwdm like :单位+'%'
and b.jh=a.jh and b.jh=e.jh
and e.rq between :第一日期 and :第二日期
and (e.c_cc like '%调%' or e.c_cs like '%调%' or e.c_bs like '%调%' or e.c_bj like '%调%' )
有两个这样的子查询,放到临时表中,来简化你的语句。
a.zyq,a.qk,e.jh,(isnull(e.c_cc,'')+isnull(e.c_cs,'')+isnull(e.c_bs,'')+isnull(e.c_bj,'')) as "内容",
datediff(dd,dateadd(dd,-5,e.rq),b.rq) as "num1",
b.rq as "qrq",b.cc as "qcc",b.cs as "qcs",b.bj as "qbj",b.bs as "qbs",b.scsj as "qscsj",
b.rcyl1 as "qrcyl1",b.rcyl as "qrcyl",b.hs as "qhs",b.dym_new as "qdym_new",b.bx as "qbx",b.bz as "qbz",
e.rq ,convert(varchar(10),e.rq,120) as "调参日期1"
from tjc01 a,tba01 b,tba01 e
where a.jb=1 and e.dwdm like :单位+'%'
and b.jh=a.jh and b.jh=e.jh
and e.rq between :第一日期 and :第二日期
and (e.c_cc like '%调%' or e.c_cs like '%调%' or e.c_bs like '%调%' or e.c_bj like '%调%' )
有两个这样的子查询,放到临时表中,来简化你的语句。
用charindex或者paxindex