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 |
|
oahu9872
Posting Yak Master
112 Posts |
Posted - 2005-08-09 : 09:39:54
|
| I have a column in my table called "zone", and the value in each record is either 1, 2, 3, 4, or 5. i need to write a sql statement that will print out each zone number only once, followed by all records with that zone, without repeating the zone number . . .Zone 1 record record recordZone 2 record recordI would appreciate any help I could get. Thanks. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-09 : 09:42:46
|
| Can you give some sample data with expected result?MadhivananFailing to plan is Planning to fail |
 |
|
|
oahu9872
Posting Yak Master
112 Posts |
Posted - 2005-08-09 : 09:50:16
|
| Let's say I have a table with 3 columns: event, location, zone...Columns = Event, Location, ZoneRecord 1 = A, New York, 1Record 2 = B, Boston, 1Record 3 = C, Chicago, 2Record 4 = D, Detroit, 2I want the output to be something like . . .1, A, NewYork, B, Boston, 2, C, Chicago, D, DetroitSo it prints out the zone ID (1 or 2) one time followed by each record in that zone without repeating a zone ID until it comes to a new one. I figure I need a loop with some if..else and maybe a case statement. I'm kind of lost on this one. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
oahu9872
Posting Yak Master
112 Posts |
Posted - 2005-08-09 : 09:53:57
|
| That link looks like it will get me started. Thanks for the help. |
 |
|
|
oahu9872
Posting Yak Master
112 Posts |
Posted - 2005-08-09 : 11:04:18
|
| Madhivanan,The code from that link was exactly what I needed. It works like it should now. Thanks. |
 |
|
|
|
|
|
|
|