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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need a SQL to get the output
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tpratyush
Starting Member

India
17 Posts

Posted - 09/30/2013 :  03:39:24  Show Profile  Reply with Quote
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

Edited by - tpratyush on 09/30/2013 03:40:23

VasiAnu
Starting Member

India
9 Posts

Posted - 09/30/2013 :  05:46:04  Show Profile  Reply with Quote
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
  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.33 seconds. Powered By: Snitz Forums 2000