|
I want to create a dynamic varchar variable like 'B0001'. if the last charcater of the variable exceeds 9 then the variable should look like 'B0010' and if the last character exceeds 99 the variable should look like 'B0100' and so on. Means the length of the variable should be fixed i.e 5 and the last number should be auto incremental like 'B0008','B0009','B0010' ,'B0011' and so on. Also if the last three digits exceeds 99 the variable should look like 'B0099','B0100','B0101' and so on
(comments are locked)
|
|
It seems to me that you are just wanting to return an integer with leading zeroes to form a 6 character string. Something like this would achieve what you want: You could wrap this into a function to make the code re-usable and also allow for different lengths etc. This should put you on the right track though. Seems like OP asked for only 5 characters long string ;) But it fulfills the core requirement though.
Jan 27 '12 at 03:03 AM
robbin
Woops, you're right. I'll change that now.
Jan 27 '12 at 03:05 AM
WilliamD
(comments are locked)
|
|
You need to let us know how the implementation would be? If you would pass an integer then it could be done as
(comments are locked)
|
|
You can use stuff to solve the problem, but you should reconsider if you really should do it. A varchar(5) takes 7 bytes and an integer only takes 4 bytes and that may affect the performance.
(comments are locked)
|

