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 |
vision.v1
Yak Posting Veteran
72 Posts |
Posted - 2012-10-26 : 09:44:50
|
Hi,i have one table in which i have multiple records data for single employeeid in need to show that employee result in single record IF OBJECT_ID('tempdb.dbo.#tempEmployeeEarningsSummary') IS NOT NULL DROP TABLE #tempEmployeeEarningsSummary CREATE TABLE #tempEmployeeEarningsSummary ( employeeID INT NULL, clientName VARCHAR(50), clientCode VARCHAR(3) NULL, ADPBonusCode VARCHAR(100) NULL, bonusAmount MONEY ) INSERT #tempEmployeeEarningsSummary VALUES('2308','gg','650','INCENTIVES','100.00')INSERT #tempEmployeeEarningsSummary VALUES('2310','gg','650','BONUS','35.99')INSERT #tempEmployeeEarningsSummary VALUES('2310','gg','650','INCENTIVES','35.66')select * from #tempEmployeeEarningsSummaryI need below output employeeID clientName clientCode ADPBonusCode bonusAmount ADPBonusCode bonusAmount2310 gg 650 BONUS 35.99 INCENTIVES 35.66 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-10-26 : 10:00:41
|
Why do you take the incentives 35.66 rather than 100?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
vision.v1
Yak Posting Veteran
72 Posts |
Posted - 2012-10-26 : 10:03:02
|
quote: Originally posted by nigelrivett Why do you take the incentives 35.66 rather than 100?both are different employeeids==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
|
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-10-26 : 13:37:51
|
Since you didn't say, it appears that you either want a random row or the one with the smallest bonus. Here is a a guess:SELECT TOP 1 *FROM #tempEmployeeEarningsSummaryWHERE EmployeeID = 2310ORDER BY BonusAmount ASC |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-26 : 15:12:40
|
seems like the below to meSELECT employeeID,clientName,clientCode,MAX(CASE WHEN ADPBonusCode = 'BONUS' THEN ADPBonusCode END) AS ADPBonusCode1,MAX(CASE WHEN ADPBonusCode = 'BONUS' THEN bonusAmount END) AS bonusAmount1, MAX(CASE WHEN ADPBonusCode = 'INCENTIVES' THEN ADPBonusCode END) AS ADPBonusCode2,MAX(CASE WHEN ADPBonusCode = 'INCENTIVES' THEN bonusAmount END) AS bonusAmount2 FROM TableGROUP BY employeeID,clientName,clientCodeHAVING COUNT(DISTINCT ADPBonusCode) >1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|