February 22, 2013 at 11:54 am
So, I am sure this is a pretty simple query, but I am stumped.
I have a query
SELECT T1.LoadStatsPODSPolicyTrID, T2.PolicyTrID, T1.LoadStatsPODSPolicyEventTrID, T2.PolicyEventTrID
FROM Staging.LoadStats T1 LEFT JOIN Policy.PolicyEvent T2 ON T1.LoadStatsPODSPolicyTrID = T2.PolicyTrID
WHERE T2.PolicyTrID = 3179656
AND ISNULL(LoadStatsPODSPolicyEventTrID, '') <> PolicyEventTrID
And the results are
LoadStatsPODSPolicyTrID PolicyTrID LoadStatsPODSPolicyEventTrID PolicyEventTrID
3179656 3179656 NULL 4960367
3179656 3179656 NULL 5615389
3179656 3179656 NULL 6865778
3179656 3179656 5615389 4960367
3179656 3179656 5615389 6865778
3179656 3179656 6865778 4960367
3179656 3179656 6865778 5615389
but what I want is
LoadStatsPODSPolicyTrID PolicyTrID LoadStatsPODSPolicyEventTrID PolicyEventTrID
3179656 3179656 NULL 4960367
Basically, I need the row out of LoadStats where the LoadStatsPODSPolicyEventTrID is NULL and the PolicyEventTrID is not (to fill in the blanks)
February 22, 2013 at 12:40 pm
SQL STEWIE (2/22/2013)
So, I am sure this is a pretty simple query, but I am stumped.
You are right this is probably a pretty simple query. However with no ddl or sample data it is impossible for anyone on this side of the internet. Please take a few minutes to read the article in my signature about best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply