SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Group by specific date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Redser
Starting Member

Ireland
9 Posts

Posted - 06/19/2012 :  06:00:46  Show Profile  Reply with Quote
I have two tables Application & Decision. Each Application can have many decisions. Each decision has a PK of Decision_ID, FK Application_ID and a DecisionDate

I’m trying to identify only those applications where the latest decision is prior to a specific date.

Example: Identify Applications were all decisions were made in 2011

If an application had 3 decisions, 2 in Nov/2011 and 1 in Feb/2012 I don’t want it returned.

If all 3 decisions were made in 2011 then I want it to returned the Application_ID

I know this code doesn't work but it's my starting point.

use Database
select Application_ID from tbl_Decision
where DecisionDate < '2012-01-01'
group by Application_ID.

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/19/2012 :  06:27:56  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
select Application_ID
from tbl_Decision
group by Application_ID
having max(DecisionDate) < '2012-01-01'


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Redser
Starting Member

Ireland
9 Posts

Posted - 06/19/2012 :  08:17:46  Show Profile  Reply with Quote
Thanks for you help nigelrivett. Much appreciated

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000