我需要在SQL Server 2005下生成多个随机值,以某种方式无法正常工作
with Random(Value) as ( select rand() Value union all select rand() from Random )select top 10 * from Random
什么是首选的解决方法?
您是否尝试过类似的方法(位于http://weblogs.sqlteam.com):
CREATE VIEW vRandNumber AS SELECT RAND() as RandNumber GO
创建一个功能
CREATE FUNCTION RandNumber() RETURNS float AS BEGIN RETURN (SELECT RandNumber FROM vRandNumber) END GO
那么您就可以像普通选择一样在选择中调用它了。dbo.RandNumber(),* from myTable
或从他们的评论中:
select RAND(CAST(NEWID() AS BINARY(6))), * from myTable