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)
sunny-jAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Try this:

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

Open in new window

0
ste5anSenior DeveloperCommented:
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.
1
Éric MoreauSenior .Net ConsultantCommented:
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

sunny-jAuthor Commented:
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)
0
Éric MoreauSenior .Net ConsultantCommented:
easiest way to get the milliseconds is to use DatePart:
DATEPART(ms, GETDATE())

Open in new window

0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
better attach random number (0-9999) at the end of your string as the password is already has unique characters taken from the first and last names.

SET [Password]=' SUBSTRING(LastName,2,3) + SUBSTRING(FirstName,1,3)+ (SELECT CAST(RAND() * 10000 AS INT) )

Open in new window

0
ste5anSenior DeveloperCommented:
First of all: Don't store passwords at all. This is a security issue. Store only a hash.

As it is about passwords: I don't see any sense to have easy to break passwords in a test environment.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sunny-jAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.