Hi,[This is about the same solution as jimf's post - I was a bit late with the submit button].I hope this helps - I'm not definitive I've fully understood the question, so this may not be correct. If it isn't and more detail is given, I can come up with a different/altered solution.If the goal is to, for the stated record, have 25 resultant records [with the pair value incrementing from 1-25 based on the values in Cable Low/Cable High, this should help.First, let's create a numbers table. This is useful in doing these types of joins where ranges of numbers are needed. You can read more about numbers tables in my blog at [url]http://www.helpwithsql.com[/url].-- If using SQL 2000, replace @singleNumbers with #singleNumbers for all of these queriesDECLARE @singleNumbers TABLE( num INT) -- Make this a permanent table - it is useful having a numbers table.CREATE TABLE Numbers ( num INT)DECLARE @counter INTSET @counter = 0 While @counter < 10BEGIN INSERT INTO @singleNumbers VALUES(@counter) SET @counter = @counter + 1END insert into NumbersSELECT ( n1000place.num*1000 + n100place.num*100 + n10place.num*10 + n1place.num) AS 'number'FROM @singleNumbers n1place CROSS JOIN @singleNumbers n10placeCROSS JOIN @singleNumbers n100placeCROSS JOIN @singleNumbers n1000placeORDER BY number
Now, let's populate some data to work with:create table Cables(elementid int, cable varchar(10), cableLow int, cableHigh int)insert into Cables values('122334','xx',1, 25)insert into Cables values('444444','yy',1, 15)insert into Cables values('444444','zz',16, 22)Here's the query to get the result:select elementid, cable, n.num From Cables c1inner join Numbers n on n.num >= cableLow and n.num <= cableHigh
I hope this helps. If I misinterpreted the question, please respond.Visit http://www.helpwithsql.com