CREATE TABLE #tblleavetransaction (EMPID INT, LeaveFromDate Date, LeaveTODate Date)
INSERT INTO #tblleavetransaction
SELECT 431, '01-02-2013', '01-04-2013' --MM-DD-YYYY
UNION ALL
SELECT 431, '01-12-2013', '01-18-2013'
UNION ALL
SELECT 431, '01-02-2014', '01-04-2014'
UNION ALL
SELECT 431, '01-12-2014', '01-18-2014'
UNION ALL
SELECT 431, '01-27-2014', '02-07-2014'
UNION ALL
SELECT 431, '02-02-2014', '02-04-2014'
UNION ALL
SELECT 431, '02-08-2014', '02-09-2014'
UNION ALL
SELECT 431, '02-20-2014', '03-09-2014'
DECLARE @PassingFromParam DATE, @PassingToParam DATE
1) While passing this parameter
SET @PassingFromParam = '2014-01-05' --YYYY-MM-DD
SET @PassingToParam = '2014-01-29' --YYYY-MM-DD
Result set should be like.
Emid LeaveFromDate LeaveTODate
431 01-02-2014 01-04-2014
431 01-12-2014 01-18-2014
431 01-27-2014 01-29-2014 ---changed
2) While passing this parameter
SET @PassingFromParam = '2014-02-02' --YYYY-MM-DD
SET @PassingToParam = '2014-02-15' --YYYY-MM-DD
Result set should be like.
Emid LeaveFromDate LeaveTODate
431 02-02-2014 02-07-2014 ---changed
431 02-02-2014 02-04-2014
431 02-08-2014 02-09-2014
3) While passing this parameter
SET @PassingFromParam = '2013-01-01' --YYYY-MM-DD
SET @PassingToParam = '2014-12-1' --YYYY-MM-DD
Result set should be like.
Emid LeaveFromDate LeaveTODate
431 01-02-2013 01-04-2013
431 01-12-2013 01-18-2013
431 01-02-2014 01-04-2014
431 01-12-2014 01-18-2014
431 01-27-2014 02-07-2014 ---Here no change same record
431 02-02-2014 02-04-2014
431 02-08-2014 02-09-2014
431 02-20-2014 03-09-2014
-------------------------------------------------------------------------------------------