Finding Numbers in between two numbers

  • Thread starter Thread starter Balaji
  • Start date Start date
B

Balaji

Hi
I want to find a number in between tow constant numbers in a single query
and it should return as rows.
(note : i dont want to resut from a table)

for eg. if i am having number 1 and 10. i should get the numbers inbetween 1
to 10 as rows
thanks
 
Balaji said:
Hi
I want to find a number in between tow constant numbers in a single
query
and it should return as rows.
(note : i dont want to resut from a table)

for eg. if i am having number 1 and 10. i should get the numbers
inbetween 1
to 10 as rows
thanks
In the criteria cell for the column put:
Between [FromValue:] And [ToValue:]

Regards

Peter Russell
 
Balaji,

I do not know if I understood your question, but the following stored
procedure returns the numbers between the two parameters as rows.

ALTER PROCEDURE NumbersBetween
(
@First int,
@Last int
)
AS
SET NOCOUNT ON

DECLARE @Counter int

CREATE TABLE #T
( Num int )

SET @Counter = @First
WHILE (@Counter < @Last-1)
BEGIN
SET @Counter = @Counter + 1
INSERT INTO #T (Num) VALUES (@Counter)
END

SELECT Num FROM #T

RETURN

Rod Scoullar
 
You can use the query with case statement

eg. select case when 50 between 10 and 60 then 50 end

Ok
 
Back
Top