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 |
awebb
Starting Member
1 Post |
Posted - 2010-02-16 : 13:04:51
|
Hi, How do I change the data in a select column from a number to a specific character. ie I need number 1 to change to a and number 2 to change to b.thanks, |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-16 : 13:11:24
|
you need to use a set of case when statements or create a mapping table with values and corresponding alphabets and take join with it on number values and add alphabet column in select list.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-02-16 : 13:20:54
|
Depending on your needs you can might be able to do a simple ASCII to CHAR conversion.. Or you might need to map as Visakh has suggested. For example:DECLARE @Foo TABLE (Val INT)INSERT @FooSELECT 1UNION ALL SELECT 2UNION ALL SELECT 3UNION ALL SELECT 4SELECT Val, CHAR(96 + Val) AS NewCharFROM @Foo-- ORSELECT Val, CASE WHEN Val BETWEEN 1 AND 3 THEN CHAR(96 + Val) ELSE CAST(Val AS CHAR(1)) END AS NewCharFROM @Foo-- ORSELECT Val, CASE WHEN Val = 1 THEN 'a' WHEN Val = 2 THEN 'b' WHEN Val = 3 THEN 'c' ELSE CAST(Val AS CHAR(1)) END AS NewCharFROM @Foo |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-17 : 02:06:20
|
quote: Originally posted by awebb Hi, How do I change the data in a select column from a number to a specific character. ie I need number 1 to change to a and number 2 to change to b.thanks,
What if there is a number 983745? MadhivananFailing to plan is Planning to fail |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-17 : 02:19:40
|
quote: Originally posted by madhivanan
quote: Originally posted by awebb Hi, How do I change the data in a select column from a number to a specific character. ie I need number 1 to change to a and number 2 to change to b.thanks,
What if there is a number 983745? MadhivananFailing to plan is Planning to fail
may be what he want is ihcgde ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-17 : 03:55:55
|
quote: Originally posted by visakh16
quote: Originally posted by madhivanan
quote: Originally posted by awebb Hi, How do I change the data in a select column from a number to a specific character. ie I need number 1 to change to a and number 2 to change to b.thanks,
What if there is a number 983745? MadhivananFailing to plan is Planning to fail
may be what he want is [b]ihcgde[/i] ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I think you meant ihcgde MadhivananFailing to plan is Planning to fail |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-17 : 04:00:43
|
quote: Originally posted by madhivanan
quote: Originally posted by visakh16
quote: Originally posted by madhivanan
quote: Originally posted by awebb Hi, How do I change the data in a select column from a number to a specific character. ie I need number 1 to change to a and number 2 to change to b.thanks,
What if there is a number 983745? MadhivananFailing to plan is Planning to fail
may be what he want is [b]ihcgde[/i] ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
I think you meant ihcgde MadhivananFailing to plan is Planning to fail
exactly..sorry i messed up the formatting tags ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|