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 |
starnold
Yak Posting Veteran
83 Posts |
Posted - 2007-03-26 : 08:43:25
|
I am trying to get the latest contract dates, my SQL so far is:Select A.subr_nbr, max(cont_strt_dt),B.SUBR_STAT_CD-- Contracts tablefrom [PC SMART].dbo.CONT A--subscriber detailsJOIN [CONTRACTS].DBO.SUBR_STAT BON A.SUBR_NBR = B.SUBR_NBRand A.countrycode = b.countrycode--contract typewhere A.CONT_CHRG_TYP_CD = 'N'and A.COUNTRYCODE = 'GBR'--exclude inactive contractsand B.subr_stat_cd not like 'D'group by A.subr_nbr, cont_strt_dt,B.SUBR_STAT_CDThis gives me all the contracts per subscriber. What I need is to get the latest for each subscriber? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-26 : 08:56:41
|
group by A.subr_nbr , cont_strt_dt ,B.SUBR_STAT_CDPeter LarssonHelsingborg, Sweden |
 |
|
starnold
Yak Posting Veteran
83 Posts |
Posted - 2007-03-26 : 08:57:59
|
But I need the other 3 columns as well? If I take them out it won't allow me to run the query |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-26 : 09:04:40
|
Something similar toselect t1.col1, t1.col2, t1.col3from table1 as t1where t1.col4 = (select max(t2.colA) from table2 as t2 where t2.colB = t1.col1 and t2.ColR = t1.Col7)Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|