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 |
HardHabit
Starting Member
12 Posts |
Posted - 2008-07-21 : 00:02:38
|
Please help me with this problem...This is my tableCity Street Range TypeABERDEEN BARBOUR DR 200-208 EABERDEEN BARBOUR DR 201-209 Oand I want the result look like thisCITY ADDRESS Range TypeABERDEEN BARBOUR DR 0 EABERDEEN BARBOUR DR 2 EABERDEEN BARBOUR DR 4 E ABERDEEN BARBOUR DR 6 EABERDEEN BARBOUR DR 8 EABERDEEN BARBOUR DR 1 OABERDEEN BARBOUR DR 3 OABERDEEN BARBOUR DR 5 OABERDEEN BARBOUR DR 7 OABERDEEN BARBOUR DR 9 Oany help would be highly appreciated....Thanks in advance.... |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-21 : 01:21:17
|
[code]DECLARE @TABLE TABLE( City varchar(10), Street varchar(10), Range_s int, Range_e int, Type CHAR(1))INSERT INTO @TABLESELECT 'ABERDEEN', 'BARBOUR DR', 200, 208, 'E' UNION ALLSELECT 'ABERDEEN', 'BARBOUR DR', 201, 209, 'O'SELECT t.City, t.Street, n.n, t.TypeFROM @TABLE t INNER JOIN ( SELECT n = 0 UNION ALL SELECT n = 1 UNION ALL SELECT n = 2 UNION ALL SELECT n = 3 UNION ALL SELECT n = 4 UNION ALL SELECT n = 5 UNION ALL SELECT n = 6 UNION ALL SELECT n = 7 UNION ALL SELECT n = 8 UNION ALL SELECT n = 9 ) n ON n <= t.Range_e - t.Range_s AND ( (t.Type = 'E' AND n % 2 = 0) OR (t.Type = 'O' AND n % 2 = 1) )/*City Street n Type ---------- ---------- ----------- ---- ABERDEEN BARBOUR DR 0 EABERDEEN BARBOUR DR 2 EABERDEEN BARBOUR DR 4 EABERDEEN BARBOUR DR 6 EABERDEEN BARBOUR DR 8 EABERDEEN BARBOUR DR 1 OABERDEEN BARBOUR DR 3 OABERDEEN BARBOUR DR 5 OABERDEEN BARBOUR DR 7 O(9 row(s) affected)*/[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
HardHabit
Starting Member
12 Posts |
Posted - 2008-07-21 : 01:58:59
|
Thanks khtan!Your code is great!...but i have another problem regarding the code that you give to me., What if i have the range of 100 or 1000? (sorry for not mentioning it earlier )....or do you have other idea regarding my problem |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|