How create a String value for represent some values in select results?
In my Select i have this result:
name | type |
-----+------+
booo | A |
xooo | B |
dooo | A |
I need a way in SQL SERVER to replace A for "Abstract" and开发者_开发技巧 B for "Ball" Thanks, Celso
Create another table with this mapping and use joins.
type | long_name |
-----+-----------+
A | Abstract |
B | Ball |
C | Cat |
WITH Strings(type,description)
AS
(
SELECT 'A', 'Abstract' UNION ALL
SELECT 'B', 'Ball'
)
SELECT y.foo, s.description
FROM YourTable y
JOIN Strings S ON S.type = y.type
You also might look at the CASE function in SQL Server, depending on what you're trying to do.
http://msdn.microsoft.com/en-us/library/ms181765.aspx
select name as "name",
(case type
when 'A' then 'Abstract'
when 'B' then 'Ball'
end) as "Type"
from MyTable
order by name
精彩评论