Search This Blog

Tuesday, 22 April 2014

Generate unique number in sql server

DECLARE @Result nvarchar(255);
    DECLARE @Random float;
    SET @Random  =  RAND( (DATEPART(mm, GETDATE()) * 100000 )
                    + (DATEPART(ss, GETDATE()) * 1000 )
                    + DATEPART(ms, GETDATE() )) ;
    SET @Random  = (10000000000) * @Random;
    Set @Result = convert(nvarchar(25), convert(bigint, @Random));

    select  'A_ '+ @Result

SELECT  CONVERT(varchar(255), NEWID()) RandomNumber;

IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Table_Name' AND  COLUMN_NAME = 'Column_Name')
                ALTER TABLE  'Table_Name' ADD 'Column_Name ' nvarchar(255)  NULL

1 comment:

  1. It was so nice article and useful to Informatica learners. we also provide Dotnet Course online training our Cubtraining is leader in providing Software Training

    ReplyDelete