Finding Numbers in between two numbers

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
 
P

Peter Russell

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
 
R

Rod Scoullar

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
 
P

Prasanth

You can use the query with case statement

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

Ok
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top