select a.wlbh,nf,yf,wldj from t_wl a,t_jqxx b,t_czzq c where a.wlbh=b.wlbh and a.cgrq>=c.qsrq and a.cgrq<=c.zzrq and nf=year(dateadd(month,-1,a.cgra)) and yf=month(dateadd(month,-1,a.cgra))
and a.cgra>=convert(datetime,convert(char(8),getdate(),120)+'01')
union all
select a.wlbh,nf,yf,wldj from t_wl a,t_jqxx b,t_czzq c where a.wlbh=b.wlbh and a.cgrq>=c.qsrq and a.cgrq<=c.zzrq and nf=c.nf and yf=c.yf
and a.cgra<convert(datetime,convert(char(8),getdate(),120)+'01')
and a.cgra>=convert(datetime,convert(char(8),getdate(),120)+'01')
union all
select a.wlbh,nf,yf,wldj from t_wl a,t_jqxx b,t_czzq c where a.wlbh=b.wlbh and a.cgrq>=c.qsrq and a.cgrq<=c.zzrq and nf=c.nf and yf=c.yf
and a.cgra<convert(datetime,convert(char(8),getdate(),120)+'01')
and a.cgra>=convert(datetime,convert(char(8),getdate(),120)+'01')
union all
select a.wlbh,nf,yf,wldj,cgsl from t_wl a,t_jqxx b,t_czzq c where a.wlbh=b.wlbh and a.cgrq>=c.qsrq and a.cgrq<=c.zzrq and nf=c.nf and yf=c.yf
and a.cgra<convert(datetime,convert(char(8),getdate(),120)+'01')
and a.cgra>=convert(datetime,convert(char(8),getdate(),120)+'01')
union all
select a.wlbh,nf,yf,wldj from t_wl a,t_jqxx b,t_czzq c where a.wlbh=b.wlbh and a.cgrq>=c.qsrq and a.cgrq<=c.zzrq and nf=c.nf and yf=c.yf
and a.cgra<convert(datetime,convert(char(8),getdate(),120)+'01')