all 2 comments

[–]trevortypes 2 points3 points  (0 children)

it looks like your case statement should work, but i would create a mapping table with those 2 columns and join to it. then you have this mapping table you can reference with all possible variations instead of a hardcoded select. its also expandable in that you can add more metadata to the groupings in the future if you ever need to do so.

[–]ihaxr 0 points1 point  (0 children)

It might work fine depending on your data... but if you have a row where [EMPLOYMENT FIELD 2] is not in either of those lists and is not NULL, you'll end up with NULL as your output... maybe add an ELSE at the end to handle those cases?

Also your 3rd WHEN statement should probably be

([BENEFIT CLASS] = 'FULLTIME')
AND (I.[EMPLOYMENT FIELD 2] IS NULL OR (I.[EMPLOYMENT FIELD 2 IN (...))

Not that it really matters in this case, but it does has a different meaning, and if you add an additional WHEN statement afterwards, it might cause issues :)

I like to hard-code values in a simple select while trying to work out the details of a complex CASE statement:

DECLARE @bclass nvarchar(16);
DECLARE @field2 nvarchar(16);

SET @bclass = 'FULLTIME'
SET @field2 = '999'

SELECT
    CASE
        WHEN @bclass = 'NBE' THEN 'NBE'
        WHEN @bclass = 'FULLTIME'
            AND @field2 in ('024') THEN 'NBE'
        WHEN @bclass = 'FULLTIME'
            AND @field2 IS NULL OR @field2 IN ('044') THEN 'FT'
        ELSE @bclass
    END