请帮我组合SQL查询 [英] Please help in my combine SQL query

查看:79
本文介绍了请帮我组合SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select t1.schemeno,t2.monyr,t2.expenamt,t1.disp,CASE WHEN t1.Premonth IS NULL THEN 'Null' else t1.Premonth END as PreMon,t1.san_no,t1.sch_amount,t1.schdate from (Select  sum(expen.amount)
 as Premonth ,expen.schemeno,sch_mas.disp,sch_mas.sch_amount, sch_mas.san_no , CONVERT(varchar, sch_mas.sdate, 106)as schdate 
  from [dbo].[expen]   inner join sch_mas on expen.schemeno=sch_mas.sch_no  where schemeno='W2/2013/11516' and exp_date<'2013-04-01' and 
   passingDate is not null  group by sch_mas.disp, expen.schemeno,sch_mas.sch_amount,sch_mas.sdate,sch_mas.san_no ) as
    t1 inner join (Select SUM(expen.amount) as expenamt, monyr,schemeno from expen  where exp_date>'2013-03-31' and exp_date<'2014-03-31'
	and schemeno='W2/2013/11516' group by monyr,schemeno) as t2 on t1.schemeno=t2.schemeno 





我的尝试:



i尝试过preminth列值null然后null但是所有数据都得到了。



但是当premonth列值为null时查找错误所有查询数据null找到



What I have tried:

i have tried when premonth column value null then null but all data get.

but error is found my query when premonth column value null all query data null found

推荐答案

你应该替换你的premonth列

isnull(t1.premonth,'')
You should be replace your premonth column from
isnull(t1.premonth,'')


这篇关于请帮我组合SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆