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:20:37
|
| 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 |
|
|
Thiyagu_04
Starting Member
37 Posts |
Posted - 2009-01-05 : 02:58:42
|
| select distinct id,(select IntValue1 from pvt where id=p.id and Typeofintvalue='Tax') as 'Tax',(select IntValue1 from pvt where id=p.id and Typeofintvalue='Income') as 'Income' from tablename p |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-01-05 : 03:59:55
|
quote: Originally posted by Thiyagu_04 select distinct id,(select IntValue1 from pvt where id=p.id and Typeofintvalue='Tax') as 'Tax',(select IntValue1 from pvt where id=p.id and Typeofintvalue='Income') as 'Income' from tablename p
See the link posted. Peso showed how to do it effecientlyMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|