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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 where exists (select... ) OR exists(select...) ??

Author  Topic 

cwfontan
Yak Posting Veteran

87 Posts

Posted - 2010-05-19 : 17:58:14
I need to make my query
So i need to select all the rows where endDate is NULL
if it has an endDate then SElect the MAX for that ID

select *
From v
where startdate < getdate AND
(enddate is NULL OR Exists (
select MAX(endDate) as maxEndDate
FROM d
WHERE d.ID = v.id)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-20 : 09:35:21
select * from v
where
(
startdate < getdate() AND
startdate = (select MAX(endDate) as maxEndDate FROM d WHERE d.ID = v.id)
)
OR
startdate is null


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -