Select Same row X number of times

  • I am trying to do a monte carlo simulation within SQL

    I have a table containing unique product numbers, and what I want to do, is return each product 10'000 times with a random number next to it;

    I can return one row for each product with

    SELECT

    prodmo,

    rnd=(SELECT RAND((convert(varbinary, newid()))))

    FROM

    PriceMoveDemo

  • Something like this ? ...

    with cteRand

    as

    (

    Select top(1000) abs(checksum(newid())) as Rand

    from sys.columns a cross join sys.columns b cross join sys.columns b

    )

    Select *

    from <yourtable> cross join cteRand



    Clear Sky SQL
    My Blog[/url]

  • Cheers that has seemed to do the trick

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply