March 15, 2020 at 12:51 pm
Need to replace this CASE statement in Where clause with something else (not CASE...), AND/OR (?). Anyway, the task is to get rid of Case statement in Where clause but I am not seeing how. Does anyone have an idea?
SELECT….<column list>
FROM CA_Leaves CL
WHERE CL.C_Status = 'New'
AND 1 = CASE WHEN @i_PARAM1_field = @i_PARAM3_field THEN 1
WHEN @i_PARAM1_field <> @i_PARAM3_field AND CL.class_id = @Other_CL_Id THEN 1
ELSE 0
END;
Likes to play Chess
March 15, 2020 at 1:10 pm
what attempts have you made so far?
that is a fairly simple case of replacing with a combination of "and" and "or"
March 15, 2020 at 1:28 pm
I did this
but test result from resting the entire SP (before and after) that this statement is a part of was different, that's why I doubted.
AND (@i_PARAM1_field = @i_PARAM3_field OR ( @i_PARAM1_field <> @i_PARAM3_field AND CL.class_id = @Other_CL_Id ))
Likes to play Chess
March 15, 2020 at 1:55 pm
--OK, let me have another attempt at this post!
Your logic seems solid.
I think you need to compare the two sets of results, identify the differences and see whether you can make sense of it from there.
It would be interesting to hear more; please post back with findings.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
March 15, 2020 at 2:29 pm
As Phil said it seems correct.
so in order to test it to ensure that the 2 queries work the same way test the individual selects in isolation of the proc - easy to setup - copy and paste code (old and new) and declare/set the variables - when you manage them to give the same results for the different combinations of parameters then you know the code is correct - if proc is giving different results then the error is somewhere else.
March 15, 2020 at 7:44 pm
SELECT….<column list>
FROM CA_Leaves CL
WHERE CL.C_Status = 'New'
AND (@i_PARAM1_field = @i_PARAM3_field
OR (@i_PARAM1_field <> @i_PARAM3_field
AND CL.class_id = @Other_CL_Id))
Why do you want to get rid of the CASE? Do you think it will be anymore efficient?
March 16, 2020 at 11:54 am
This was removed by the editor as SPAM
March 16, 2020 at 2:04 pm
Thanks, my CASE is what I was worried about. If all I have to do is change the ORs to ANDs, then I'm happy. I was able to find plenty of examples of CASE within WHERE, but nothing which looked similar to this.
What exactly were you worried about with the CASE statement?
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply