Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL SUBQUERY MAX AND COUNT IN SSMS(2008)

Author  Topic 

kond.mohan
Posting Yak Master

213 Posts

Posted - 2012-03-16 : 08:02:47


Hi,

I have written subquery in(SSMS) sql server 2008

my subquery i have written to pick recent record have used max max function

outside query i have calculated count of bills

here i need to use suquery maxdate and date2 DATEDIFF IN MY MAIN query

----------------------------------------
this is my subquery



left join (select DISTINCT FBH.BILL_ID as id,
MAX(FBH.vfd_bod_Date) as date1 ,
FBM.PARTY_CODE
,FBM.BILL_PARAM_TYPE,


FBH.BP_LIAB_CRNCY
from dwh_staging..FBH

left join dwh_staging..FBM on FBM.BILL_ID =FBH.BILL_ID

where fbh.bill_stat in ('R')
--and FBM.PARTY_CODE ='25041777'
--and FBM.PARTY_CODE ='12624727'

group by
FBM.BILL_PARAM_TYPE ,
fbm.party_code,FBH.DUE_DATE ,
FBH.BP_LIAB_CRNCY ,FBH.BILL_ID
having MAX(FBH.vfd_bod_Date)>FBH.DUE_DATE


) nfb on nfb.id =FBM.BILL_ID
AND nfb.PARTY_CODE =FBM.PARTY_CODE
and nfb.date1 =FBH.VFD_BOD_DATE
and nfb.BILL_PARAM_TYPE =FBM.BILL_PARAM_TYPE
and nfb.BP_LIAB_CRNCY =FBH.BP_LIAB_CRNCY

expected out put is

countofbills count(1-15)days count(16-30)days count(31-45)days

10 5 3 2
50 30 5 15


am

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-16 : 11:23:43
with a partial query and not having information else how do you expect someone to help you out on this?

Post sample data in below format and then you will get quick help

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -