简体   繁体   English

如何在 SQL 的 SELECT INTO 语句中指定列格式?

[英]How to specify column format in SELECT INTO statements in SQL?

I have a table [TABLE1] with columns A , B , C for example.例如,我有一个表[TABLE1]其中包含ABC列。 Already have data inside.里面已经有数据了。 There is a new column, say B2 , that I want to add into a new table [TABLE2] .有一个新列,例如B2 ,我想将其添加到新表[TABLE2]

Due to weird permission setup , I can create table, I can SELECT INTO , but I cannot change the columns settings.由于奇怪的权限设置,我可以创建表,我可以SELECT INTO ,但我不能更改列设置。

I have the following code:我有以下代码:

SELECT A, B, '' as B2, C
INTO TABLE2
FROM TABLE1;

This give us more or less what I want.这或多或少地给了我们我想要的东西。 But B2 is now varchar(1) .但是B2现在是varchar(1) I want to specify it to be varchar(5) within the above code.我想在上面的代码中将它指定为varchar(5) How can I achieve this?我怎样才能做到这一点?

Thanks, Jack谢谢,杰克

投射到你想要的类型:

SELECT A, B, CAST('' as VARCHAR(5)) as B2, C

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM