Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Change Gender Qualification

Author  Topic 

Dasman
Yak Posting Veteran

79 Posts

Posted - 2011-07-21 : 14:52:31
Hello All,

In one of my tables of date I have GENDER column that has either 1 or 2 signifying either male of female, respectively.

How can I change that and or have an output column called GENDER 2 with MALE and FEMALE?

1 -> Male
2 -> Female

Thanks,
Shijit

==========================
Pain is Weakness Leaving the Body.

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-07-21 : 15:01:50
Select case when Gender = 1 then 'Male'
when Gender =2 then 'Female' else null end as ColumnName
From TableName

If you want to change that code to word, make sure the column is varchar or char with enough lenght to hold Female and run Update query... or Create new column to run update on that

Or create another table which has descripton of gender code 1, 2 and join against that in the query...

Sorry if I misunderstood your question.
Go to Top of Page

Dasman
Yak Posting Veteran

79 Posts

Posted - 2011-07-21 : 15:03:33
Just to check - this does not change the table?
I do not want it to change the table.

Thanks!
Dasman

==========================
Pain is Weakness Leaving the Body.
Go to Top of Page

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-07-21 : 15:05:52
Select will not change the table as it will just pull the data, update will change the table if the update doesn't fail.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-07-21 : 16:35:17
ISO 5218 defines gender codes as:

0 = not known,
1 = male,
2 = female,
9 = not applicable

You could use a CASE expression/function to output a string or you could create a domain table and join to it.
Go to Top of Page
   

- Advertisement -