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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need a SQL to get the output

Author  Topic 

tpratyush
Starting Member

17 Posts

Posted - 2013-09-30 : 03:39:24
Input
ID Emp No. Start Date End Date Pattern
1234 5678 3/5/2010 3/6/2010 A1
1234 5678 3/5/2010 3/6/2010 B1
1234 5678 3/7/2010 3/8/2010 A1
1234 5678 3/7/2010 3/8/2010 B1
1234 5678 3/9/2010 3/10/2010 A1
1234 5678 3/9/2010 3/10/2010 B1
1234 5678 3/11/2010 3/12/2010 A1
1234 5678 3/11/2010 3/12/2010 B1
1234 5678 3/13/2010 3/14/2010 A1
1234 5678 3/13/2010 3/14/2010 B1
1234 5678 3/15/2010 3/16/2010 A1
1234 5678 3/15/2010 3/16/2010 B1
Output
ID Emp No. Authorized Start Date Authorized End date Pattern
1234 5678 3/5/2010 3/16/2010 A1
1234 5678 3/5/2010 3/16/2010 B1

In the input table, the Pattern are present as A1, B1.
I need the output as showed. The latest end date will be the Auth. End date
similarly, the earliest start date will be the Auth. Start Date.

Thanks and Regards,
Pratyush Tripathy

VasiAnu
Starting Member

9 Posts

Posted - 2013-09-30 : 05:46:04
elect DISTINCT ID,EmpNo,MIN(StartDate) StartDate ,MAX(EndDate) EndDate,Pattern from TableName
Group by ID,EmpNo,Pattern


Thanks,
VA.
Go to Top of Page
   

- Advertisement -