database - How to merge two SQL SELECTqueries into one query in SQL Server CE? -


i have 2 select queries, return more 45 , less 45. need merge these 2 queries one. if possible, how can achieve it?

query 1:

select      sum(tbl_invoices.pendingamount) morethan45      tbl_debit  inner join      tbl_invoices on tbl_debit.invoice = tbl_invoices.invoice        (tbl_invoices.state = - 1)      , (datediff(day, tbl_debit.purchasedate, getdate()) >= 45) 

query 2:

select      sum(tbl_invoices.pendingamount) lessthan45      tbl_debit  inner join      tbl_invoices on tbl_debit.invoice = tbl_invoices.invoice        (tbl_invoices.state = - 1)      , (datediff(day, tbl_debit.purchasedate, getdate()) < 45) 

i tried following query returns error.

select (query 1),(query 2) 

please me solve issue.

you should able use case, like;

select    sum(case when (datediff(day, tbl_debit.purchasedate, getdate()) >= 45)            tbl_invoices.pendingamount else 0 end) morethan45,   sum(case when (datediff(day, tbl_debit.purchasedate, getdate()) < 45)            tbl_invoices.pendingamount else 0 end) lessthan45 tbl_debit  inner join tbl_invoices    on tbl_debit.invoice = tbl_invoices.invoice   (tbl_invoices.state = - 1) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -