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 |
|
JuSlaughter
Starting Member
1 Post |
Posted - 2009-11-25 : 10:27:26
|
| Thats a rubbish title, sorry. First post so please be gentle.I have to write a query for our ecommerce team where they want me to return data for car insurance policies. What they want is if the driver has multiple cars, each car should appear as a column in the recordset instead of multiple rows in the recordset.For example, I get 3 rows of data, each with its own make and modelMake ModelFord FocusVauxhall AstraHonda CivicIt needs to look likeMake1 Model1 Make2 Model2 Make3 Model3Ford Focus Vauxhall Astra Honda CivicIf there are only 2 cars, only Make1 and Make2, etc will show, if there are 10, I need Make10, Model10.Does that make sense?Any help would be massively appreciated.Cheers |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-11-25 : 13:09:51
|
I normally like to do this type of thing with the front end report rather than the back end database, but you can do this with a standard pivot in sql, but keep in mind unless you use dynamic sql, you will need to predetermine the maximum # of Make's you want. Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|