简体   繁体   English

SELECT'ING INTO新表时如何添加NULL列?

[英]How do I add a NULL column when SELECT'ing INTO a new table?

I have a statement like this: 我有这样的声明:

SELECT field1, field2, MyField = NULL
INTO NewTable
FROM OldTable

This does what I want with one exception: the field I created MyField and filled with NULL is an INT type and I'd like it to be a VARCHAR type. 这样做我想要的只有一个例外:我创建MyField并填充NULL的字段是INT类型,我希望它是VARCHAR类型。 I don't know how to modify the same statement to create the new field with the VARCHAR type. 我不知道如何修改相同的语句来创建VARCHAR类型的新字段。

Thanks. 谢谢。

尝试用。替换null

CAST(null as VARCHAR)
SELECT field1, field2, convert(varchar, NULL) as MyField
INTO NewTable
FROM OldTable

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将SELECT的结果添加为现有表中的新列? - How do I add the result of a SELECT as a new column in an existing table? 当空表中的列为NULL时,如何插入表中 - How do Insert into a table when one the column in the empty table is NULL 添加另一个表时,如何更改表的列中的值? - How do I change a value in a column in a table when I add another table? 如何计算平均评分并将新列添加到MySQL表中以记录此内容 - How do I work out average rating and add a new column to my MySQL table to record this 创建 SQL 视图时,如何添加一个数组列,该列是另一个表中列的记录集合 - When creating an SQL view, how do I add an array column that is a collection of records from a column in another table 我如何在C#中使用LINQ“选择null作为”列” - How do I “select null as ”Column" Using LINQ in C# 如何选择插入到选择一个表中,而该表在主键列中已经有值而不添加新行? - How do I select insert into select a table which already has values in the primary key column without adding new rows? 如何从另一个表列中选择一个表? - How do I select a table from another table column? 如何仅将同一表中的多行和 select 连接到没有 NULL 值的列 + 为该列添加别名 - How to join multiple rows from same table and select only the column with not NULL values + add an alias to the column 如何通过选择语句为新列指定类型 - How do i specify a type for a new column through a select statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM