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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert value from a table to another table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 04/30/2013 :  15:50:19  Show Profile  Reply with Quote
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

Please help

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/30/2013 :  17:11:31  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000