Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SQL Server中将一个表中的选定列插入另一个表中的选定列_Sql_Sql Server_Insert - Fatal编程技术网

在SQL Server中将一个表中的选定列插入另一个表中的选定列

在SQL Server中将一个表中的选定列插入另一个表中的选定列,sql,sql-server,insert,Sql,Sql Server,Insert,我不熟悉SQL Server,希望找到解决方案 我有两个表employees和new\u employees 表employees包含以下列: id(pk) | username | phonenumber | createdby | deptid |date id(pk) | name, p_number | dept_id | ext_no | salary 表new_employees包含以下列: id(pk) | username | phonenumber | createdby

我不熟悉SQL Server,希望找到解决方案

我有两个表
employees
new\u employees

employees
包含以下列:

id(pk) | username | phonenumber | createdby | deptid |date
id(pk) | name, p_number | dept_id | ext_no | salary
new_employees
包含以下列:

id(pk) | username | phonenumber | createdby | deptid |date
id(pk) | name, p_number | dept_id | ext_no | salary
我想将表
new\u employees
中包含选定列
name
p\u number
dept\u id'
的所有记录插入表
employees
username
phonenumber
deptid
列中

但是在表
employees
createdby
date
列中,我想输入两个值“John”和
getDate()


请帮助我编写此场景的查询。

如果混淆是关于混合表中的值和文字值,则可以使用以下形式的语法:

INSERT INTO Table (...)
SELECT col1, ... 'John', GetDate()
  FROM AnotherTable;

如果混淆是关于混合表中的值和文字值,则可以使用以下形式的语法:

INSERT INTO Table (...)
SELECT col1, ... 'John', GetDate()
  FROM AnotherTable;

您要查找的语句是
INSERT
,它允许您指定要插入的列,并且您可以(除其他外)插入
SELECT
语句的结果@mendosi yes through insert and select语句我可以处理这两个表的公共列,但如何在表Employees中为createdby和date列设置值您要查找的语句是
insert
,它允许您指定要插入的列以及可以插入的列(除其他外)插入
SELECT
语句的结果@mendosi是的,通过insert和select语句,我可以处理这两个表的公共列,但如何将createdby和date列的值放入表employees中