Hello,
I'm trying to accomplish the below requirement. Please help.
declare @emp_pct_by_prod table ( prod_cd varchar(20), emp_id int, begin_date datetime, end_date datetime, pct int ) declare @trans_by_prod table ( prod_cd varchar(20), conf_date datetime, buyer_name varchar(100) ) declare @start_date datetime declare @stop_date datetime insert into @emp_pct_by_prod values ('abc123',1,'07/10/2015','07/11/2015',20) insert into @emp_pct_by_prod values ('abc123',2,'07/10/2015','07/11/2015',80) insert into @emp_pct_by_prod values ('abc123',3,'07/11/2015','07/12/2015',20) insert into @emp_pct_by_prod values ('abc123',2,'07/12/2015','07/30/2015',100) insert into @trans_by_prod values ('abc123','07/10/2015','Rich') insert into @trans_by_prod values ('abc123','07/11/2015','John') insert into @trans_by_prod values ('abc123','07/12/2015','Mark') insert into @trans_by_prod values ('abc123','07/29/2015','Shan') Case 1: set @start_date= '07/10/2015' set @stop_date= '07/29/2015' output: emp_id conf_date pct buyer_name 1 07/10/2015 20 Rich 2 07/10/2015 80 Rich 3 07/11/2015 20 John 2 07/11/2015 80 John 2 07/12/2015 100 Mark 2 07/29/2015 100 Shan Case 2: set @start_date= '07/11/2015' set @stop_date= '07/11/2015' output: emp_id conf_date pct buyer_name 3 07/11/2015 20 John 2 07/11/2015 80 John Case 3: set @start_date= '07/10/2015' set @stop_date= '07/10/2015' output: emp_id conf_date pct buyer_name 1 07/10/2015 20 Rich 2 07/10/2015 80 Rich