如何创建特定类型的列? [英] How to create a column of a specific type?

查看:17
本文介绍了如何创建特定类型的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一列添加到 Select 并使该列具有特定类型.

How would I add a column to a Select and have that column be of a specific type.

例如选择公司、城市、会费、0 作为 NewColumn1、123.12 作为 NewColumn2但我希望 NewColumn1 的类型为 bit,而 NewColumn2 的类型为 Real

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

哦,我使用的是 SQL Server 2005.

Oh, I'm using SQL Server 2005.

推荐答案

您可以使用 CAST

Select  Company,    
        City, 
        Dues, 
        CAST(0 AS BIT) As NewColumn1, 
        CAST(123.12 AS REAL As NewColumn2 
FROM    @Table

查看 CAST 和 CONVERT (Transact-SQL) .

这篇关于如何创建特定类型的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆