How to create a column of a specific type?

独自空忆成欢 提交于 2019-12-25 00:09:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!