从另一个表创建表,并在sql中添加其他列 [英] create table from another table with additional columns in sql

查看:196
本文介绍了从另一个表创建表,并在sql中添加其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从另一个表创建表,其中包含sql中的其他列

create table from another table with additional columns in sql

推荐答案

这样的事情:



Something like this:

SELECT  [Statecode]
      ,[state]
  FROM [scott_test].[dbo].[test]
  
Statecode	state
1	DLI
2	MH
3	UP
2	DLI  
  
select 
 statecode, state, CAST (0 as integer) as new_column
into #states
from [scott_test].[dbo].[test];

select * from #states;

statecode	state	new_column
1	DLI	0
2	MH	0
3	UP	0
2	DLI	0





您经常需要使用CAST / CONVERT来使新列成为所需的数据类型。

Scott



You often need to use CAST/CONVERT to get the new column to be the desired datatype.
Scott


这篇关于从另一个表创建表,并在sql中添加其他列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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