Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find multiple instances of field1 where field2 does not match

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi,

I have the following data:

create table #temp (filename varchar(20), filedate datetime)
insert into #temp values ('D0062277.001','2005-12-15 08:57:00.000')
insert into #temp values ('D0062277.001','2005-12-15 08:57:00.000')
insert into #temp values ('D0062284.001','2005-12-19 08:31:00.000')
insert into #temp values ('D0062284.001','2013-01-20 08:31:00.000')
insert into #temp values ('D0062288.001','2002-01-25 05:08:00.000')
insert into #temp values ('D0062288.001','2002-01-25 05:08:00.000')
insert into #temp values ('D0062296.001','2005-05-04 11:27:00.000')
insert into #temp values ('D0062296.001','2005-05-04 11:27:00.000')


Each 'Filename' exists more than one time. I would like to pinpoint those files that exist more than once, but where the 'filedate' differs.

For example, 'D0062284.001' exists once with date 2005-12-19 and once with 2013-01-20.

Can anyone think of a way I can do this?

Thanks!
 
How about something like:
Code:
;WITH cte AS (SELECT DISTINCT FileName, FileDate FROM #temp) 
SELECT FileName, COUNT(*) as cnt 
FROM cte 
group by FileName 
Having COUNT(*) > 1;

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
This might work

Select filename, COUNT(fd.filename) CNT
From(
Select filename, FileDate, COUNT(fileDate) Date From temp
Group by filename, FileDate
) fd
Where fd.Date = 1
Group By fd.filename
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top