22,209
社区成员
发帖
与我相关
我的任务
分享
select a.spid,a.spbh,a.spmch,a.tongym,a.shpgg,a.jixing,a.shengccj,a.dw,a.leibie,
b.shl,a.hshsj,a.hshjj,b.shl*a.hshjj as je ,b.pihao,b.sxrq,c.huowname,datediff(day,getdate(),
convert(datetime,case when substring(b.sxrq,6,2)='02' and len(b.sxrq)=7 then b.sxrq+'-01'
when substring(b.sxrq,6,2) in ('01','03','05','07','08','10','12') and len(b.sxrq)=7 then sxrq+'-01'
when substring(b.sxrq,6,2) in ('04','06','09','11') and len(b.sxrq)=7 then b.sxrq+'-01' else b.sxrq end)) as 到期天数
from spkfk a join sphwph b on a.spid=b.spid
join huoweizl c on b.hw=c.hw
where b.shl>0 and
(len(b.sxrq)=7 or len(b.sxrq)=10) and b.sxrq<>''
and b.sxrq is not null and (substring(b.sxrq,5,1)='-' or substring(sxrq,8,1)='-')
and (substring(b.sxrq,6,2)>='01' and substring(b.sxrq,6,2)<='12' or substring(b.sxrq,9,2)>='01' and substring(b.sxrq,9,2)<='31')
and c.hwbh like '01' and c.duifbsh='ZDA' and a.dyfl='医疗器械'
order by b.sxrq,a.spbh,b.pihao