Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem using GETDATE() to generate a key
Message
From
22/08/2013 11:52:47
 
 
To
22/08/2013 07:27:28
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01580950
Message ID:
01580988
Views:
27
>>>its not my data. I'm loading data into a table thats normally populated by a different system and I'm emulating what that other system does to build a key.
>>
>>
>>I see that your key is 20 chars. Try using SYSDATETIME(). There are 7 digits after the decimal point (GetDate() only has 3)
>>
>

Hey Nicholas,

Considering the constraints you are operating under using GETDATE(), I am assuming you can remove extraneous characters from the string using only the digits to form the key ( 20 chars ).

This is not foolproof, but if other options do not work out, you could try forming the key from the GETDATE() function, then executing a query on the resulting key string to determine the existence of the resulting key. If it exists, create a short string ( 1-3 chars ) using a randomizer, append these chars and re-try the query. If found, try again, etc. If not found, attempt your INSERT and trap any resulting constraint error so another attempt can be made.

As I mentioned this is not foolproof ( a redesign would be better ) but you may be able to experiment with this approach for the specific conditions under which you are operating to get a working solution.

Bill
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Previous
Reply
Map
View

Click here to load this message in the networking platform