Sunday, 2 March 2014

Nested case statement



Nested Case Statement:






-- divide actors up into male/female, and by age
SELECT
ActorName,
ActorGender,
CONVERT(char(10),ActorDob,103) AS Dob,

-- male or female
CASE ActorGender
WHEN 'Male' THEN

CASE
WHEN Year(ActorDob) < 1980 THEN 'Man'
ELSE 'Boy'
END

WHEN 'Female' THEN

CASE
WHEN Year(ActorDob) < 1980 THEN 'Woman'
ELSE 'Girl'
END

ELSE 'Other'

END AS Category

FROM
tblActor

No comments:

Post a Comment