|
I am trying to use a case statement in a where clause with an IN - it's erroring arount the in - I am not sure quite what the correct syntax is but if the my supplier is = acme - they want to see more actions then the rest of the suppliers...
(comments are locked)
|
|
That's not how CASE is used, it's not a logical construct that you can use for filtering, it returns a scalar value. You could do: Two things I'd like to mention with your query: If SPLR_ACCT_ID is an int, you'd probably get a better result if you do: At least that was the case in SQL Server 2000 and I think I've tested it with SQL Server 2005 as well. What it does is: If @SPLR_ID is null, you check if SPLR_ACCT_ID is between the minimum and the maximum values of an integer, otherwise it checks if SPLR_ACCT_ID is between @SPLR_ID and @SPLR_ID. The optimizer at least used to handle this better than col=@val or @val is null Second thing: If you can, avoid using LIKE and '%something%' because that comparison can not use an index seex, it will have to scan to find its values. @Magnus Ahlkvist I was also thinking in terms of (ACME and IN (A, B)) or (NOT ACME and = A) but then realised that the way I have it in my answer is probably cheaper, but then again, this predicate does not appear to be slim anyways, so perhaps it does not really matter.
Jun 30 '11 at 03:50 PM
Oleg
@Oleg You're right, I wasn't paying attention to that both logical paths included 'CHANGE'.
Jun 30 '11 at 11:13 PM
Magnus Ahlkvist
(comments are locked)
|
|
You can restate it like this (the logic is still the same): This way all records with CHNG_TYP = 'CHANGE' will be shown regardless of the supplier name and additionally, the ACME supplier's record with additional change type of REMOVAL will be shown as well. Oleg
(comments are locked)
|

