Coffeehouse Post

Single Post Permalink

View Thread: Error: Invalid use of 'rand' within a function.
  • User profile image
    bitmask

    Just be aware if you do:

      UPDATE MyTAble
        SET MyNumber = SELECT dbo.RandomDate(RAND())

    Then every row updated will have the same random date.

    If you need a random date for every row (hopefully you don't, or this is a one time run), you can use a view as I suggested earlier:

      CREATE VIEW RandomNumber
      AS
        SELECT RAND() AS number

    Then inside of your UDF:

      SELECT number FROM RandomNumber

    will give you a random number. Just remember the caveats from my first post.