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 2000 Forums
 SQL Server Development (2000)
 COMBINE RECORDS IN A SINGLE ROW

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 table

SELECT *
FROM dbo.empBenefits q
WHERE (StartDate IN
(SELECT TOP 2 STARTDATE
FROM EMPBENEFITS
WHERE 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 As

EmployeeNo 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

Posted - 2006-04-18 : 08:57:32
Refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -