问题
How would I add a column to a Select and have that column be of a specific type.
For example Select Company, City, Dues, 0 As NewColumn1, 123.12 As NewColumn2 But I want NewColumn1 to be of type bit, and NewColumn2 to be of type Real
Oh, I'm using SQL Server 2005.
回答1:
You can use CAST
Select Company,
City,
Dues,
CAST(0 AS BIT) As NewColumn1,
CAST(123.12 AS REAL As NewColumn2
FROM @Table
Have a look at CAST and CONVERT (Transact-SQL) .
来源:https://stackoverflow.com/questions/1920086/how-to-create-a-column-of-a-specific-type