SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

ougesh
Starting Member

Mauritius
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
VALUES(123,123,123)

Please help

James K
Flowing Fount of Yak Knowledge

3638 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  
 New 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.03 seconds. Powered By: Snitz Forums 2000