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
 SELECT

Author  Topic 

Freddie
Starting Member

29 Posts

Posted - 2008-11-18 : 12:14:28
Hello:

I would like to

SELECT * from table WHERE a.date = b.date and status = 'A'

but if a.date = b.date and status 'A' doesn't exist i want status 'P'.

Is there a function for this?


a_date b_date status

2008-07-27 00:00:00 2008-07-27 00:00:00 A
2008-07-27 00:00:00 2008-08-27 00:00:00 P
2008-06-27 00:00:00 2008-06-27 00:00:00 P


Thank You

F.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-18 : 12:17:55
[code]SELECT a_date,b_date,MIN(status) AS status from table WHERE a_date = b_date and (status = 'A' or status='P') GROUP BY a_date,b_date[/code]
Go to Top of Page

Freddie
Starting Member

29 Posts

Posted - 2008-11-18 : 12:23:21
Works Great...Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-18 : 12:24:35
cheers
Go to Top of Page
   

- Advertisement -