SQL語法:
SELECT [EmployeeID]
,[EmployeeName]
,[Title], (rand() * 10000) as rand_num
FROM [Northwind].[dbo].[Employees]
其中我透過許多不同的方式嘗解決這個問題,但可惜都無法解決,後來終於找到一個解決,透過下列的語法,即可讓每一列產生的亂數值都不相同,在此提供給大家。
SQL語法:
SELECT [EmployeeID]
,[EmployeeName]
,[Title]
,(ABS(CAST(NEWID() AS binary(6)) %10000)) rand_num
FROM [Northwind].[dbo].[Employees]
參考連結:
RAND (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms177610.aspx
Mathematical Functions (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms177516.aspx
關鍵字:SQL Server、Rand、Randomize、seed
沒有留言:
張貼留言