Предположим, мы создали временную таблицу
CREATE TABLE #DeleteMe(startNo INT , endNo INT )
, затем вставляем все записи в временную таблицу. Например, от 1 до 100
;WITH nums AS
(SELECT 1 AS startNo,1 AS endNo
UNION ALL
SELECT startNo + 1 AS startNo,endNo + 1 AS endNo
FROM nums
WHERE nums.startNo <= 99)
INSERT INTO #DeleteMe
SELECT *
FROM nums
/ * Вот начальная основная часть, которую вы хотите .... * /
DECLARE @inputstart as int ,@inputend AS INT
SET @inputstart= 2
SET @inputend = 50
SELECT * FROM #DeleteMe WHERE
convert(INT,startNo) BETWEEN Convert(INT,CASE WHEN isnull(@inputstart,'')='' THEN startNo ELSE isnull(@inputstart,'') END)
AND Convert(INT, CASE WHEN isnull(@inputend,'')='' THEN endNo ELSE isnull(@inputend,'') END)