February 5, 2008 at 7:58 am
I am having some trouble thinking about how to write this T-SQL statement, and I know some of you guys can do it in your sleep.
To simplify my data, I have a table with two IDs and two Dates
Here is a record:
AttachID <- unique key
PoleID <- Foreign Key, not Unique in this Table
AttachDate <- datetime
PoleDT <- datetime
In my data, each PoleID has several AttachIDs. Both Dates can be NULL, the AttachDT can be filled in and the PoleDT Null, or both Dates can be filled in.
I am trying to return a list of PoleIDs where for that ID all the records with that PoleID have AttachDTs but their PoleDTs are NULL. So if there are three records with that PoleID, all three have AttachDTs and no PoleDTs. If the AttachDT in NULL for any of the three, I don't want it in my list.
Any help would be greatly appreciated.
February 5, 2008 at 8:23 am
SELECTPoleID,
FROMTable1
GROUP BYPoleID
HAVINGMAX(CASE WHEN AttachDate IS NOT NULL AND PoleDT IS NULL THEN 0 ELSE 1 END) = 0
N 56°04'39.16"
E 12°55'05.25"
February 5, 2008 at 8:25 am
Thank you
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply