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 |
andooran
Starting Member
2 Posts |
Posted - 2009-01-05 : 02:24:17
|
I have a table, Table1, that contains three columnsID, IntValue1, TypeOfIntValueSample rowsID IntValue1 TypeOfIntValue1 20 Tax1 220 Income2 22 Tax3 400 IncomeTypeOfIntValue can be either "Tax" or "Income"Each ID can have at most two rows of data - Tax/IncomeNow I want to combine data for same ID into a single row. Given that I can only use SQL 2000 compliant T-SQL, how do I write this query? (Cannot use Pivot operation etc.)Expected result is like thisID Tax Income1 20 2202 22 NULL3 NULL 400I dont want the exact query but would appreciate any guidance like suggestions to use certain type of query etc. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-05 : 02:34:59
|
SELECT ID,MAX(CASE WHEN TypeOfIntValue = 'Income' THEN Intvalue ELSE NULL END) AS Income,MAX(CASE WHEN TypeOfIntValue = 'Tax' THEN Intvalue ELSE NULL END) AS TaxFROM Table1GROUP BY IDORDER BY ID E 12°55'05.63"N 56°04'39.26" |
|
|
|
|
|