Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. lower and upper limit problem

lower and upper limit problem

Scheduled Pinned Locked Moved Database
tutorialhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wajans
    wrote on last edited by
    #1

    I have a table with 3 columns as follows: lower upper id 12 20 100 100 150 200 I want to select range of numbers based on lower and upper column. For example I want to display numbers between 12 to 20 or from 100 to 150. How to do it. thanks in advance.

    B P 3 Replies Last reply
    0
    • W wajans

      I have a table with 3 columns as follows: lower upper id 12 20 100 100 150 200 I want to select range of numbers based on lower and upper column. For example I want to display numbers between 12 to 20 or from 100 to 150. How to do it. thanks in advance.

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      wajid ansari wrote:

      numbers between 12 to 20 or from 100 to 150.

      Exists stored in table or not?


      I Love T-SQL "Don't torture yourself,let the life to do it for you."

      1 Reply Last reply
      0
      • W wajans

        I have a table with 3 columns as follows: lower upper id 12 20 100 100 150 200 I want to select range of numbers based on lower and upper column. For example I want to display numbers between 12 to 20 or from 100 to 150. How to do it. thanks in advance.

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        Here I made a sample test with temporary table. create table #numbers (value int ) declare @i as int set @i = (select min(number) from myTable) while @i<(select max(number) from myTable)-1 begin set @i=@i+1 insert into #numbers values (@i) end select * from #numbers drop table #numbers


        I Love T-SQL "Don't torture yourself,let the life to do it for you."

        1 Reply Last reply
        0
        • W wajans

          I have a table with 3 columns as follows: lower upper id 12 20 100 100 150 200 I want to select range of numbers based on lower and upper column. For example I want to display numbers between 12 to 20 or from 100 to 150. How to do it. thanks in advance.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Your question doesn't give much idea of what you want, so here are some choices:

          CREATE FUNCTION GetRange
          (
          @Lower INTEGER
          ,
          @Upper INTEGER
          )
          RETURNS @IntegerRange TABLE
          (
          Member INTEGER
          )
          AS
          BEGIN
          WHILE @Lower<=@Upper
          BEGIN
          INSERT INTO @IntegerRange VALUES (@Lower)
          SET @Lower=@Lower+1
          END

          RETURN 
          

          END

          SELECT * FROM GetRange ( 12 , 20 )

          CREATE FUNCTION GetRangeById
          (
          @ID INTEGER
          )
          RETURNS @IntegerRange TABLE
          (
          Member INTEGER
          )
          AS
          BEGIN
          DECLARE @Lower INTEGER
          DECLARE @Upper INTEGER

          SET @Lower = (SELECT \[Lower\] FROM Series WHERE ID=@ID)
          SET @Upper = (SELECT \[Upper\] FROM Series WHERE ID=@ID)
          
          WHILE @Lower<=@Upper
          BEGIN
          	INSERT INTO @IntegerRange VALUES (@Lower)
          	SET @Lower=@Lower+1
          END
          
          RETURN 
          

          END

          SELECT * FROM GetRange ( 100 )

          CREATE FUNCTION GetAllRanges
          (
          )
          RETURNS @IntegerRange TABLE
          (
          ID INTEGER
          ,
          Member INTEGER
          )
          AS
          BEGIN
          DECLARE @ID INTEGER
          DECLARE @Lower INTEGER
          DECLARE @Upper INTEGER

          DECLARE SeriesCursor CURSOR FOR SELECT \* FROM Series 
          
          OPEN SeriesCursor
          
          FETCH NEXT FROM SeriesCursor
          INTO @ID , @Lower , @Upper
          
          WHILE @@FETCH\_STATUS=0
          BEGIN
          	WHILE @Lower<=@Upper
          	BEGIN
          		INSERT INTO @IntegerRange VALUES (@ID , @Lower)
          		SET @Lower=@Lower+1
          	END
          
          	FETCH NEXT FROM SeriesCursor
          	INTO @ID , @Lower , @Upper
          
          END
          
          CLOSE SeriesCursor
          
          RETURN 
          

          END

          SELECT * FROM GetAllRanges()

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups