views:

33

answers:

1

I have a BIT column with gender (0,1) and want to replace 0 and 1 in the resulting view with the words "man" and "woman". Can i do this right in the view with some system finction or i have to write my own function to do that?

+3  A: 

You can just use a CASE statement like below. Think about what you're trying to do though - perhaps it would be better to return 0 and 1, but convert to the right text in the UI...that's what I'd do.

SELECT CASE Gender WHEN 0 THEN 'Man' WHEN 1 THEN 'Woman' END AS Gender
FROM YourTableOrView
AdaTheDev
In the project i did the same in the UI ;) so this question was just for the interest, because ive tried to do this in the DB first, but didnt know how to manage this operation :) thanks for the answer, this case is just the thing i wanted!
nihi_l_ist