| Author |
Topic |
|
RyanAustin
Yak Posting Veteran
50 Posts |
Posted - 2009-01-05 : 16:49:46
|
| I have a table that records values from a call tracking software. There can also be multiple records for each call id. What I would like to be able to do is that if there are 3 assignments for one call id, and one of those records has a resolution date missing, to exclude that record from a query. callid recvddate assignee dateacknow dateresolv112546 2007-01-15 Bob 2007-01-16 2007-01-16112546 2007-01-15 Tim 2007-01-17 2007-01-17112546 2007-01-15 Jerry 2007-01-17 13265 2007-06-15 Bob 2007-06-16 2007-06-1813265 2007-06-15 Janet 2007-06-16 2007-06-1913265 2007-06-15 Jerry 2007-06-16 2007-06-1813265 2007-06-15 Jim 2007-06-16 2007-06-18So if I were to query this, I only want to return 13265. |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2009-01-05 : 16:59:27
|
| Would this work?SELECT callid, recvddate, assignee, dateacknow, dateresolv FROM YourTableName WHERE dateresolv is not nullthat would give you all the records that had a dateresolv date.To get all the records without a resolve date simply change the whereclause to dateresolv is null |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-01-05 : 17:01:48
|
quote: Originally posted by revdnrdy Would this work?SELECT callid, recvddate, assignee, dateacknow, dateresolv FROM YourTableName WHERE dateresolv is not nullthat would give you all the records that had a dateresolv date.To get all the records without a resolve date simply change the whereclause to dateresolv is null
I think he wants to exclude all CallID records if even one of those CallIDs is null, not just the one row where it is null. |
 |
|
|
RyanAustin
Yak Posting Veteran
50 Posts |
Posted - 2009-01-05 : 17:03:14
|
| Unfortunately that wouldn't work. If I use DATERESOLV IS NOT NULL then it still returns that one callid. I don't want to return a callid if there is still a dateresolv'd that needs to be set. (If that makes sense) |
 |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2009-01-05 : 17:30:57
|
| Hmm ok well maybe use two tables..1. Create a table to hold all ID's of all records with NULL in dateresoled.Select callid into TableA from TableBwhere dateresolv is null2. Perform a left join to get records from TableB that do not have a callid in TableA. This will exclude everything that has at least 1 null value for callid.SELECT * FROM TableBLEFT OUTER JOIN TableAON TableB.callid = TableA.callidWHERE TableA.callid IS nullsomething like that, note I didnt have time to test this..r&r |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-01-05 : 17:41:50
|
| I think I may have what you're looking for:SELECT CallID, RecvdDate, Asignee, DateAcknow, DateResolv FROM YourTableWHERE CallID NOT IN (SELECT CallID FROM YourTable WHERE DateResolv IS NULL) |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-01-05 : 17:48:32
|
| Also, if you want just the CallIDs that have no unresolved dates you can do this:SELECT DISTINCT CallIDFROM YourTableWHERE CallID NOT IN (SELECT CallID FROM YourTable WHERE DateResolv IS NULL) |
 |
|
|
RyanAustin
Yak Posting Veteran
50 Posts |
Posted - 2009-01-05 : 18:09:54
|
quote: Originally posted by Skorch I think I may have what you're looking for:SELECT CallID, RecvdDate, Asignee, DateAcknow, DateResolv FROM YourTableWHERE CallID NOT IN (SELECT CallID FROM YourTable WHERE DateResolv IS NULL)
That is is. Monday after the holidays. Brain fart. Thanks. |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-01-05 : 18:21:36
|
quote: Originally posted by RyanAustin
quote: Originally posted by Skorch I think I may have what you're looking for:SELECT CallID, RecvdDate, Asignee, DateAcknow, DateResolv FROM YourTableWHERE CallID NOT IN (SELECT CallID FROM YourTable WHERE DateResolv IS NULL)
That is is. Monday after the holidays. Brain fart. Thanks.
No problem :) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|