SQL SERVER 取 1到10隨機數字

直接用RAND的話,會取到一樣的值,所以要用newid()去滾算,
CAST(RAND(CHECKSUM(NEWID())) * 10 as INT) + 1 ,

紅字10是隨機的範圍,如果是要1~3,就把數字改成3即可。

by mhchen15 on 2 12 月, 2015 in SQL SERVER - Tags:
Tags:

There are no comments.

Name*: Website: E-Mail*:
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>