Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query using a function to map

Status
Not open for further replies.

soandos

Programmer
Oct 26, 2009
1
US
is there a way to write a query so that instead of the raw data bieng returned, it is mapped to something else?
i.e. if there is a table that looks like:

1 5 7
2 6 7
1 6 8

is there a way to run a query so that 1 gets replaced by "string" in column 1, 6 by "string2" in column two and the like?
I do not mean an update query, i just want to resulant table to display it with the strings, and not have that stored in a permanent table in the database.
 
Code:
SELECT CASE WHEN Column1 = 1
                 THEN 'String'
            ELSE CAST(Column1 as varchar(20)) END AS Column1,
       CASE WHEN Column2 = 6
                 THEN 'String2'
            ELSE CAST(Column2 as varchar(20)) END AS Column2
FROM YourTable

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top