<p>I'm running a SQL query on SQL Server 2005, and in addition to 2 columns being queried from the database, I'd also like to return 1 column of random numbers along with them. I tried this:</p>

<pre><code>select column1, column2, floor(rand() * 10000) as column3 
from table1
</code></pre>

<p>Which kinda works, but the problem is that this query returns the same random number on every row. It's a different number each time you run the query, but it doesn't vary from row to row. How can I do this and get a new random number for each row?</p>

You need to use a UDF
first:
```
```
CREATE VIEW vRandNumber
AS
SELECT RAND() as RandNumber
```
```
second:
```
```
CREATE FUNCTION RandNumber()
RETURNS float
AS
  BEGIN
  RETURN (SELECT RandNumber FROM vRandNumber)
  END
```
```
test:
```
```
SELECT dbo.RandNumber(), *
FROM <table>
```
```
Above borrowed from
Jeff's SQL Server Blog