Tuesday, 23 April 2013

Random Num Generation using Sql

Random Num Generation



Alphanumeric  Number

SELECT LEFT(CONVERT(VARCHAR(36),  NEWID()),3)+RIGHT(CONVERT(VARCHAR(36),  NEWID()),2)
o/p : 5665F
Only Number
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 = 99999 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SELECT @Random

No comments:

Post a Comment

SQL SERVER – Disk Space Monitoring – Detecting Low Disk Space on Server

CREATE PROCEDURE [CSMSDVLP].[DiskSpaceMonitor] @mailProfile nvarchar(500), @mailto nvarchar(4000), @threshold INT, @logfile nvarchar(40...