Results 1 to 2 of 2

Thread: Randomized output from stored procedure ?

  1. #1
    Eirik Kjølsrud Guest

    Randomized output from stored procedure ?

    Hi.

    I'm using stored procedures in SQL7 to return a list of items to a website where they are presented. A new requirement is to present these items in a random order on the website. I have two approaches to this one, either making the result from SQL7 random or presenting the ordered results randomly. Since the presentation logic is used several times (different country subsites), it would be the easiest way to get a randomized result from the stored procedure, which would mean that I only have to change the procedure.

    Any thoughts on how to accomplish this, that is returning a list of items but in random order, so that the presentation sequence would be different for each access to the website ??

    Any help would be appreciated : )

    Thanks!

    Eirik Kjølsrud
    Systems Developer, Apropos Internett - Norway

  2. #2
    WizKid Guest

    Randomized output from stored procedure ? (reply)

    Eirik,
    Just a thought...
    You might be able to use something like this...


    declare @x int,
    @cmd varchar(255)
    select @x = rand() * 10
    select @cmd = 'select * from service_T '
    If @x > 0
    select @cmd = @cmd + ' order by ' + convert(varchar(12), @x)
    exec(@cmd)

    - Hope it helps..


    ------------
    Eirik Kjølsrud at 7/11/01 6:03:58 AM

    Hi.

    I'm using stored procedures in SQL7 to return a list of items to a website where they are presented. A new requirement is to present these items in a random order on the website. I have two approaches to this one, either making the result from SQL7 random or presenting the ordered results randomly. Since the presentation logic is used several times (different country subsites), it would be the easiest way to get a randomized result from the stored procedure, which would mean that I only have to change the procedure.

    Any thoughts on how to accomplish this, that is returning a list of items but in random order, so that the presentation sequence would be different for each access to the website ??

    Any help would be appreciated : )

    Thanks!

    Eirik Kjølsrud
    Systems Developer, Apropos Internett - Norway

Posting Permissions

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