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 |
|
sumo
Starting Member
45 Posts |
Posted - 2002-11-27 : 11:23:09
|
Is there an easy way to expand a single record that has 2 fields as a range into single records for each value in the range? Here's some sample data that I am working with:Make Model BegYear EndYear SKUACURA CL 1998 2000 P4936267083ACURA CL 1998 2000 P4941757083ACURA CL 1998 2000 P4941767083 I'd like to take each of those records and expand them out into separate records for each year. For example, the first record above would expand into:Make Model Year SKUACURA CL 1998 P4936267083ACURA CL 1999 P4936267083ACURA CL 2000 P4936267083 I can only think of using cursors and iterating through the first query and inserting the data into a new table, but it seems that there'd be an easier, faster way through a more complex query.Any help is appreciated!TIA!Michael SumeranoTechnical Web AdministratoreKeystone.comhttp://www.ekeystone.com/Edited by - sumo on 11/27/2002 11:24:33 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-11-27 : 11:49:12
|
| Create a table with all the years in it and join to that.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-11-27 : 12:04:58
|
| As NR mentioned, you need a table of Years that just list all years in your data range.If you have that, thenSELECT Make, Model, Year, SKUFROM DataINNER JOIN YearsON Years.Year BETWEEN BegYear AND EndYearshould do the trick.- Jeff |
 |
|
|
sumo
Starting Member
45 Posts |
Posted - 2002-11-27 : 12:09:29
|
So simple, I feel stupid.  quote: Create a table with all the years in it and join to that.
Michael SumeranoTechnical Web AdministratoreKeystone.comhttp://www.ekeystone.com/ |
 |
|
|
|
|
|