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 2012 Forums
 Transact-SQL (2012)
 Help in SQL Query

Author  Topic 

Sadhu
Starting Member

14 Posts

Posted - 2014-12-19 : 00:21:03
Sample Data :

EventBID, EventID, Archived Date

E1, 1, 12/10/2014
E2, 1, 12/18/2014
E3, 1, NULL
E4, 2, NULL
E5, 2, NULL
E6, 2, NULL
E7, 3, 11/08/2014
E8, 3, NULL
E9, 4, NULL
E10, 4, NULL

I want to get the EVENTIDs that are having all the ArchiveDates for EventBIDs as NULL.

Output :
2
4

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-12-19 : 01:33:17
[code]

create table #x (EventBID varchar(10),EventID INT,[Archived Date] varchar(100))

insert into #x
select 'E1',1,'12/10/2014' union all
select 'pat',1,'12/18/2014' union all
select 'E3', 1, NULL union all
select 'E4', 2, NULL union all
select 'E5', 2, NULL union all
select 'E6', 2, NULL union all
select 'E7', 3,'11/08/2014' union all
select 'E8', 3, NULL union all
select 'E9', 4, NULL union all
select 'E10', 4, NULL

SELECT DISTINCT EventID FROM dbo.#x WHERE [Archived Date] IS NULL AND EventID NOT IN (SELECT EventID From #x WHERE [Archived Date] IS NOT NULL )

DROP Table #x
[/code]

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
   

- Advertisement -