Click here to Skip to main content
11,479,486 members (46,473 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
I need to write a Transact SQL Statement to get three different numbers that are unique in the database rounded upto three digits. How do i do this?
Posted 27-Sep-12 1:32am
Comments
Santhosh Kumar J at 27-Sep-12 6:43am
   
give some examples or output for your scenario

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,

See the below link. It might be help you to find your solution.

http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/[^]

See the Method :1
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
 
---- This will create a random number between 1 and 999
SET @Lower = 1 ---- The lowest random number
SET @Upper = 999 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SELECT @Random

Viprat
  Permalink  
v2
Comments
Maciej Los at 28-Sep-12 13:29pm
   
Good work, my 5!
Interesting link ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 255
1 Sergey Alexandrovich Kryukov 215
2 F-ES Sitecore 175
3 Richard MacCutchan 120
4 Frankie-C 104
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,441
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 27 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100