Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to generate a unique number via sql. I need to remove colon from the result set in sql itself

What I have tried:

SELECT convert(varchar, getdate(), 112)+convert(varchar, getdate(), 114)
Posted
Updated 11-Oct-22 7:19am
Comments
Dave Kreskowiak 11-Oct-22 12:24pm    
If you're trying to create a unique number, why are you using getdate? If two clients make the same request using this code, it CAN generate identical numbers.
Member 8428760 11-Oct-22 21:18pm    
Try select TRIM(';' FROM convert(varchar, getdate(), 112)+convert(varchar, getdate(), 114))

1 solution

For a unique number, don't try to generate it yourself - it will almost certain fail and cause intermittent problems which are really hard to find and fix.

Instead, look at using an IDENTITY[^] column, or a uniqueidentifier[^] column instead.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900