SQLTeam.com | Weblogs | Forums

Insert a Table based on a resultset


#1

Hai,

I want to Insert into table based on a condition.

There are 3 tables

ContLeave
Create Table ContLeave (Startdate smalldatetime , Enddate smalldatetime)
Insert Into ContLeave
Select '2016-01-03' , '2016-01-03'
Union All
Select '2016-01-10' , '2016-01-10'
Union All
Select '2016-01-15' , '2016-01-17'
Union All
Select '2016-01-24' , '2016-01-24'
Union All
Select '2016-01-26' , '2016-01-26'

(Result received from stephen hendricks)
This table contains the leave days for given month

Absentdata
Create Table Absentdata (Ecode varchar(12),Absentdate smalldatetime,LOP float)

Insert Into Absentdata
Select 'E1','2016/01/14',1
Union All
Select 'E1','2016/01/18',1
Union All
Select 'E1','2016/01/29',1
Union All
Select 'E3','2016/01/01',1
Union All
Select 'E3','2016/01/25',1
Union All
Select 'E3','2016/01/27',1
Union All
Select 'E6','2016/01/03',1
Union All
Select 'E8','2016/01/14',1
Union All
Select 'E9',2016/01/27',1

This table contains the absentees data employeewise datewise

Table in which data to be inserted

C15LL
Ecode,Absentdate

If the employee absents himself before and after a leave day, then all holidays has to inserted in C15LL

Input data sample
E1,2016/01/15
E1,2016/01/16
E1,2016/01/17
E3,2016/01/26

Thanks in advance

Regards

Nirene