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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-04-18 : 08:32:55
|
| ireh0316 writes "I Have this SQL STATEMENT to get the TOP 2 Record from the tableSELECT *FROM dbo.empBenefits qWHERE (StartDate IN(SELECT TOP 2 STARTDATE FROM EMPBENEFITSWHERE EMPBENEFITS.employeeno = q.employeeno AND Benefitcode = 'HON'ORDER BY startdate DESC))Result :EmployeeNo StartDate Salary 1 10/10/2006 5000 1 10/30/2006 8000 2 11/01/2006 4000 3 11/05/2006 5000 4 12/05/2006 3000 4 12/06/2006 8000 Data Should Show AsEmployeeNo OldSalary NewSalary 1 5000 8000 (Single Row) 2 4000 3 5000 4 3000 8000 (Single Row)The data should appear in a single row when there is a similar employee no. There will be a maximun of 2 identical employee no in the list. There are times that employee will only have a single record.How can i revise the query to appear a record in single row in case there are 2 identical employee no in the list ? Note: All data comes from a single table (EMPBENEFITS)Thank you so much." |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|