S
shadowsong
I have a table of product registrations. All entries have a product
number. Some entries have a single serial number, and some have a
range of serial numbers. I would like to remove all records containing
a range and replace them with multiple records, one per number in the
range.
For example, say I have four records:
Product Serial First Last
F21 1
F21 2 10
F11 1 10
F11 11
I would like to wave my magic query-wand and end up with my table
looking like this:
Product Serial First Last
F21 1
F21 2
F21 3
F21 4
F21 5
F21 6
F21 7
F21 8
F21 9
F21 10
F11 1
F11 2
F11 3
F11 4
F11 5
F11 6
F11 7
F11 8
F11 9
F11 10
F11 11
I know it will involve SELECT (to find the records with non-null
ranges), INSERT (to put the individual serial records in the table),
DELETE (to get rid of the range records), and x = [first] to [last]
step 1 (to generate the serial number for each record in the range -
although I'm not sure if that's the correct syntax for SQL), but I'm
not sure how to put that all together. Any ideas?
number. Some entries have a single serial number, and some have a
range of serial numbers. I would like to remove all records containing
a range and replace them with multiple records, one per number in the
range.
For example, say I have four records:
Product Serial First Last
F21 1
F21 2 10
F11 1 10
F11 11
I would like to wave my magic query-wand and end up with my table
looking like this:
Product Serial First Last
F21 1
F21 2
F21 3
F21 4
F21 5
F21 6
F21 7
F21 8
F21 9
F21 10
F11 1
F11 2
F11 3
F11 4
F11 5
F11 6
F11 7
F11 8
F11 9
F11 10
F11 11
I know it will involve SELECT (to find the records with non-null
ranges), INSERT (to put the individual serial records in the table),
DELETE (to get rid of the range records), and x = [first] to [last]
step 1 (to generate the serial number for each record in the range -
although I'm not sure if that's the correct syntax for SQL), but I'm
not sure how to put that all together. Any ideas?