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 2000 Forums
 SQL Server Development (2000)
 Comparing Records in one table

Author  Topic 

MrHicks
Starting Member

3 Posts

Posted - 2004-11-09 : 11:27:11
Sorry, that topic isn't really specific but I'm not exactly sure how to phrase it.

Basically I've been given this rather large database that someone else designed horribly, and I'm looking at one specific table. The two columns in particular I need to look at are called "archive" and "filename".

The archive column consists of either "Printed Copy" or "Electronic Copy". Each filename in this table should have two records associated with it, the "Printed Copy" record and the "Electronic Copy" record.

Is there a way to go through this entire table and basically check to make sure each unqiue filename has both a "Printed Copy" and an "Electronic Copy"... and if they don't output them?

To get a little more specific:

Filename Archive
-------- -------
aaaa "Printed Copy"
aaaa "Electronic Copy"
bbbb "Printed Copy"
bbbb "Electronic Copy"
cccc "Printed Copy"
dddd "Electronic Copy"

I would want 'cccc' and 'dddd' rows to be outputted.

nr
SQLTeam MVY

12543 Posts

Posted - 2004-11-09 : 11:43:29
select Filename
from tbl
where Archive in ('Printed Copy', 'Electronic Copy')
group by Filename
having count(distinct Archive) = 1


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

MrHicks
Starting Member

3 Posts

Posted - 2004-11-09 : 12:05:41
Thanks for the reply NR, that query gives me a "syntax error(missing operator) in query expression 'count(disctint Archive) = 1'" though.
Go to Top of Page

MrHicks
Starting Member

3 Posts

Posted - 2004-11-09 : 12:12:41
Even with distinct spelled properly it still gives that error.
Go to Top of Page
   

- Advertisement -