2016-11-19 66 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它工作:) –

相關問題