Information générale
Forum:
Microsoft SQL Server
Titre:
Need string function help
I am attempting to create a trigger which will assign a policy number to a record, and am having some trouble with the string function.
I have a field called 'lastused', which is a counter. Every time a record is added to the system, 'lastused' is incremented by 1.
The policy number format is "XXX" + several zeros + the stringed and trimmed value of 'lastused'. It is a 12 character field. For instance, if 'lastused' = 123, then the policy number should be "XXX000000123". If 'lastused' is 1234567, the the policy number should be "XXX001234567". But I am having a devil of a time getting the right number of '0' inserted between the "XXX" and the lastused number.
Current code is:
policynumber = "XXX" + stuff(str(lastused,4,(9 - len(lastused))), '0')
This gives me "XXX0 1234"
It is probably simple, but.....
Marie
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement