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.
| 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 -> Male2 -> FemaleThanks,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 ColumnNameFrom TableNameIf 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 thatOr create another table which has descripton of gender code 1, 2 and join against that in the query...Sorry if I misunderstood your question. |
 |
|
|
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. |
 |
|
|
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. |
 |
|
|
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 applicableYou could use a CASE expression/function to output a string or you could create a domain table and join to it. |
 |
|
|
|
|
|