Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-09-08 : 09:03:54
|
| rk writes "I have to write a stored procedure which wil create automated an alphanumeric primary key in the background.---this is for K type customer say:- if the previous key 'k002' then it has to generate 'K003' but again after 'k009' it has to generate 'k10'-- this is for R type customer.it start with rseries and it has to increse as above start with r." |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-09-08 : 09:27:00
|
| Something along these lines:DECLARE @MAXKey INTDECLARE @NewKey VARCHAR(10)SET @MaxKey = (SELECT MAX(CAST(RIGHT(PrimaryKey, 9) as INT)) FROM TableA)SET @NewKey = 'K' + RIGHT('000000000' + LTRIM(RTRIM(STR(@MaxKey + 1, 9))))Duane. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
|
|
|