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
 General SQL Server Forums
 New to SQL Server Programming
 selecting Max(startDate)

Author  Topic 

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2011-01-26 : 11:31:58
Hi everyone.
working on a members db

I am trying to select members from with two start dates. But only want to retreive the latest date.

ie

SELECT (INDIVIDUAL_REF), max(valid_from)
FROM dbo.s_Attribute
WHERE (ATTR_CODE_REF = 3401)
and valid_to is null
group by (INDIVIDUAL_REF), max(valid_from)
order by (INDIVIDUAL_REF)

not sure where iam going wrong

MCTS / MCITP certified

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-26 : 11:34:00
you mean this?


SELECT (INDIVIDUAL_REF), max(valid_from)
FROM dbo.s_Attribute
WHERE (ATTR_CODE_REF = 3401)
and valid_to is null
group by (INDIVIDUAL_REF)
order by (INDIVIDUAL_REF)


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

Go to Top of Page

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2011-01-26 : 11:37:35
thank you for that. but ive managed to suss it out.

And i came up with exactly the same syntax

But thank you very much
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-26 : 11:39:05
np

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

Go to Top of Page
   

- Advertisement -