Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert value from a table to another table

Author  Topic 

ougesh
Starting Member

1 Post

Posted - 2013-04-30 : 15:50:19
Hi i have a table: tblEmployee which has a column empCode(primary Key)
and i have another table tblLeave which also have column empCode(foreign Key). What i want to do is to populate tblLeave with empCode from tblEmployee, also in the query i have to add values for other fields of tblLeave.
What i am trying is:
INSERT INTO tblLeave(empCode,dateFrom,dateTo,numberOfDays)
SELECT FROM tblEmployee empCode WHERE tblEmployee.empCode=tblLeave.empCode
VALUES(123,123,123)

Please help

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-30 : 17:11:31
The syntax of the code you posted is not correct. I can help you correct the syntax - but it is not clear to me what you want to accomplish. For example, let us say you had two employees in the tblEmployee table. And nothing at all in the tblLeave table. Based on the table names, I am assuming that tblLeave is used for storing information about each employee's vacations/absences. Assuming that that is the case, if the first employee (empCode = 1) takes a week off from work starting today (20130430), what do you want to insert into tblLeave?
Go to Top of Page
   

- Advertisement -