Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can any one tell why t-sql not allowing using RAND function in side a function

SELECT  CAST (RAND() * 10000000 as varchar(20))

the error is

Invalid use of a side-effecting operator 'rand' within a function.
share|improve this question
What version of SQL are you using? It works just fine on my SQL Server 2008 R2 instance. – mrdenny Jan 22 '13 at 22:12
we use mssql 2008 enterprise edition – kumar_2002 Jan 22 '13 at 22:13
can you post the whole function? – A-K Jan 23 '13 at 1:59
I'm not sure what Denny was trying; I get the same error on my 2008 R2 instance when putting that code in a function definition. – Jon Seigel Jan 23 '13 at 3:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.