How do I generate random number for each row in a TSQL Select?

前端 未结 19 955
逝去的感伤
逝去的感伤 2020-11-22 07:03

I need a different random number for each row in my table. The following seemingly obvious code uses the same random value for each row.

SELECT table_name,          


        
19条回答
  •  情深已故
    2020-11-22 07:39

    Update my_table set my_field = CEILING((RAND(CAST(NEWID() AS varbinary)) * 10))
    

    Number between 1 and 10.

提交回复
热议问题