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.
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_CRNCYexpected out put is countofbills count(1-15)days count(16-30)days count(31-45)days 10 5 3 2 50 30 5 15am |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|