Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Posts
    32

    Unanswered: Query to create a countable list using a single value from table

    Hi,

    from a single numeric value, say 'n', in a field in a table, i'd like to create a SELECT query that produces a list from 1 to n, e.g

    if the value was 6, I would like selected back:
    1
    2
    3
    4
    5
    6

    Any pointers?
    Greg

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Why?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Feb 2004
    Posts
    32
    I'm developing a system using an Enterprise product, Metastorm e-work, that sits above SQL server. Given a Quantity value, I want to make a drop down list of the values from 1 to Quantity using the form designer that comes with the product, to allow a user to change this value.

    I'd like to do something more sophisticated than my posted request, but if there is SQL code available to do this, it will get me on the way.

    g.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    CREATE a numbers TABLE...

    SELECT Col1 from myTable99
    WHERE Col1 <= @value

    You'll use it for more than just this...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Feb 2004
    Posts
    32
    Cheers.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Originally posted by Brett Kaiser
    You'll use it for more than just this...
    so true

    similar example: generating sequential dates
    see The integers table
    (site registration may be required, but it's free)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •