|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, January 19, 2010 7:20 AM
Points: 14,
Visits: 90
|
|
I have 2 formats of date fields in 2 seperate tables. Given the selection of P or F I am attempting to do use the appropriate date range for the where clause:
WHERE 1=1 AND CASE WHEN FPCH.ProcessedDateKey >= @Beg_Date AND FPCH.ProcessedDateKey <= @End_Date THEN 'P' WHEN AR.RunCycleDate>= @pBeg_Date AND AR.RunCycleDate<= @pEnd_Date THEN 'F' END = @DateSolution AND FPCH.InventoryStatusCode in (97,98)
The P seems to work, but the F doesn't. I'm self taught, and have been programming in other languages for a long time, but I'm not sure what I'm missing here. Any help would be greatly appreciated. Thanks in advance.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
Not sure from just this little bit, but a place to start is that it will never get to F if the test for P comes up true. Case statements stop as soon as they find a true condition.
Also, why have the 1=1 in your Where clause?
I'd most likely rewrite it as:
WHERE (FPCH.ProcessedDateKey >= @Beg_Date AND FPCH.ProcessedDateKey <= @End_Date and 'P' = @DateSolution or AR.RunCycleDate>= @pBeg_Date AND AR.RunCycleDate<= @pEnd_Date and 'F' = @DateSolution) AND FPCH.InventoryStatusCode in (97,98)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, January 19, 2010 7:20 AM
Points: 14,
Visits: 90
|
|
| wow, was I over analyzing things! Thanks so much.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
You're welcome.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|