• I'll help a little further. The script you posted (althought syntactically incorrect) does exactly what the RN_MULTINOMIAL function does:

    UPDATE BOOKINGS

    SET DepartureDate

    CASE WHEN RAND() Result = Between 0 and 0.3 = Departure Date will be 2 Nights Later

    CASE WHEN RAND() Result = Between 0.3 and 0.4 = Departure Date will be 3 Nights Later

    CASE WHEN RAND ()Result >0.4 = Departure Date will be either 1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28 Nights Later

    To put this in a context that might be more familiar to you, what you'll want to do is something like this (after setting up the @MultinomialProbabilities Distribution table:

    UPDATE b

    SET DepartureDate = DATEADD(day,

    dbo.RN_MULTINOMIAL(@MultinomialProbabilities, URN), Arrivaldate)

    FROM BOOKINGS b

    CROSS APPLY (SELECT URN=RAND(CHECKSUM(NEWID()))) a

    Your boss should be happy because you used a CASE statement too (in the setup of the @MultinomialProbabilities Distribution table). 😛


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St