Link to home
Start Free TrialLog in
Avatar of sunny-j
sunny-j

asked on

unique number generator sql server

Greetings Experts,

I am looking to take something unique from this string below to add to a unique number, please can some tell me how to adjust so the result is two digits from the milliseconds numbers. thanks.
SUBSTRING(CONVERT(varchar(12),GETDATE(),113),9,13)
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this:

SELECT SUBSTRING(CONVERT(nvarchar(24),getdate(), 113),23,24)

Open in new window

I am looking to take something unique from this string

The only thing which is unique in this string is the entire string. Cause each possible substring combination has collisions.

So the question is: What are you trying to do? Please post some information about your current context.

Especially as "adding a unique string" to another "unique string" makes no sense. Cause when one part is already unique, it's not relevant whether the other part is unique or not.
Avatar of sunny-j
sunny-j

ASKER

I am sorry, I should have given more information from the start,

I want to create a password that has elements of the user's name along with something more unique. Its for a test system and later on we will allow them to create their own passwords. (adding say a 2-4 digit number to the end of password.  thanks again.

 UPDATE Table
 SET [Password]=' SUBSTRING(LastName,2,3) + SUBSTRING(FirstName,1,3)+ SUBSTRING(CONVERT(nvarchar(24),getdate(), 113),23,24)
easiest way to get the milliseconds is to use DatePart:
DATEPART(ms, GETDATE())

Open in new window

SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunny-j

ASKER

Thank you all for your comments. Given Stefan's comment, I need to go back to the drawing board and decide how secure this needs to be at this stage. Kind regards.