Try this using SUBSTRING()
function(Fiddle example):
--Declare sample table
DECLARE @T TABLE (id int identity, numCol1 int, numCol2 int)
--Add some values
INSERT @T (numCol1, numCol2)
VALUES (3, 7), (1, 4), (2, 2)
--Actual Query
SELECT *, SUBSTRING('123456789', numCol1, numCol2 - numCol1 + 1) Number
FROM @T
Above query works only with single digit numbers. Modified version (below) to work with numbers like 34, 78
SELECT *,
SUBSTRING('123456789', CONVERT(int, LEFT(numCol1,1)),
CONVERT(int, RIGHT(numCol2, 1)) - convert(int, LEFT(numCol1,1)) + 1) YourNumber
FROM @T
Note: Number column is returning a string
, can be converted to an int
using convert()
function