March 25, 2013 at 12:49 pm
Hello,
Need help with in writing a Stored Procedure for Auto Alpha Numeric Generation. If I pass an Alpha numeric in the format mentioned below , I should get next number based on the following logic:
Format : It consists of 6 digit Alpha Numeric Code , where E is constant. For ex : E00001
SP should generate like this:
E00001 to E99999 when it reaches to E99999 then 9 on left will be replaced with "A"- EA0001
EA0001 - EA9999
EB0001 - EB9999
EZ0001 - EZ9999 when it reaches EZ9999 it should be incrmented to E0A001
Thanks,
Nick
March 25, 2013 at 1:07 pm
nitin_456 (3/25/2013)
Hello,Need help with in writing a Stored Procedure for Auto Alpha Numeric Generation. If I pass an Alpha numeric in the format mentioned below , I should get next number based on the following logic:
Format : It consists of 6 digit Alpha Numeric Code , where E is constant. For ex : E00001
SP should generate like this:
E00001 to E99999 when it reaches to E99999 then 9 on left will be replaced with "A"- EA0001
EA0001 - EA9999
EB0001 - EB9999
EZ0001 - EZ9999 when it reaches EZ9999 it should be incrmented to E0A001
Thanks,
Nick
This kind of things pops up around here from time to time. The short answer is don't do this. It seems like you have a 5 character code. What happens when you need a 6th position? If you are deadset on doing this you will have to do some awful calculations and ASCII math.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 25, 2013 at 1:09 pm
Hi Sean- It always be 5 digit Code + constant.
March 25, 2013 at 1:16 pm
nitin_456 (3/25/2013)
Hi Sean- It always be 5 digit Code + constant.
The logic for this type of thing is horrible. It ends up being a scalar function and performance is not too good.
What have you tried so far?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 25, 2013 at 1:38 pm
Totally Blank , Plz see if you can suggest something.
March 25, 2013 at 1:45 pm
nitin_456 (3/25/2013)
Totally Blank , Plz see if you can suggest something.
Honestly I would suggest not doing this. The code will make your eyes bleed before you even get close to completion. The logic for this requires it to be scalar in nature. I have brute forced this type of thing in the past but seriously it is awful.
Maybe we can help find a different solution if we know more about the problem.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 25, 2013 at 2:05 pm
Totally agree, but this is the task I got to do this.
March 25, 2013 at 2:08 pm
When EZ9999 incrments to E0A001, what happens as E0A999?
March 25, 2013 at 2:11 pm
When EZ9999 incrments to E0A001, what happens as E0A999?
ans : When EZ9999 increments to E0A001
then afterwards It E0a999 will be increment to E0B001
Or What can be done is
After EZ9999 it can be incremented to EAA001
Thanks Guys for looking at the post !
March 25, 2013 at 2:19 pm
Can you use CLR? This type of heavy string manipulation is probably going to be a lot easier to work with in .NET instead of pure t-sql.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 25, 2013 at 2:44 pm
When E0A001 incremenst to E0Z999, what comes next:
E1A001?
Does that go to EZZ999? The rules for creating the Aplha part don't seem very clear to me.
I'd agree with Sean that this is a REALLY BAD scheme for creating a unique value. Columns are supposed to have a data type and data types have operations defined on them. This column would have to be a character data type but have numeric operations used upon it. Hardly ever a good idea.
March 25, 2013 at 2:54 pm
i have some old examples in my snippets, but this just goes back to the same comments all other posters have made:
bad idea. the posters so far on here all have years more experience than you, tens of thousands of posts here on SSC volunteering, and all of them are telling you you it's bad.
your rules don't even follow a mathematical calculation, so you cannot do the typical identity() on the table + calculated column I've seen as solutions.
Lowell
March 25, 2013 at 3:34 pm
Your stated incrementation method is so unusual and customized that I'd suggest just creating table with pre-generated key values; and, when you need to increment by one, instead of actual "incrementing", lookup the next value in the keys table.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
March 25, 2013 at 5:40 pm
So the idea here is to Generate 2 -3 million consecutive unique numbers by using 5 Alpha Numeric digit. Please if you can help around this will be great.
March 25, 2013 at 6:35 pm
Or convince your powers that be to change what they are asking you accomplish.
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply