2016-11-19 65 views
0

我是SQL Server的新手,希望找到解决方案。将选定的列从一个表插入到SQL Server中另一个表的选定列

我有两个表employeesnew_employees

employees有列:

id(pk) | username | phonenumber | createdby | deptid |date 

new_employees有列:

id(pk) | name, p_number | dept_id | ext_no | salary 

我要插入表new_employees所有记录与所选列namep_numberdept_id'username列, phonenumberdeptidemployees

但在表employeescreatedbydate列,我想提出两个值“约翰”和getDate();

请帮我写查询此方案。

+0

你正在寻找的语句是'INSERT',它允许您指定哪些列插入,你可以(除其他外)插入'SELECT'语句的结果。 http://www.w3schools.com/sql/sql_insert.asp – mendosi

+0

@mendosi是通过插入和选择语句我可以处理这两个表的公共列,但如何将列**的值**和**日期* *在表员工 –

回答

0

如果他的困惑是有关从表和文字值混合值,则可以使用这种形式的语法:

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

谢谢@mendosi它工作:) –

相关问题