sql how to cast a select query

sql, sql-server-2008

Solution

You just `CAST()` this way

SELECT cast(yourNumber as varchar(10))
FROM yourTable

Then if you want to `JOIN` based on it, you can use:

SELECT *
FROM yourTable t1
INNER JOIN yourOtherTable t2
    on cast(t1.yourNumber as varchar(10)) = t2.yourString

Problem

Is it possible to apply the cast function to a select statement? If yes, how? I have a query that returns a number which I have to use a string to get other info's from another table.

Original source

Related problems