Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
Hi,
I want to gernerate a unique varcahr id bsaed on city address, ID should be like this PKRKHRAL01234 (where KHR is code for city name and it will change when city name changes) how can i achieve this?
Posted

 
Share this answer
 
use a calculated column on the table which should put togather the Primary Key and the city, and whenever someone changes the city this code will change along

PKR = Static
KHR = City Column
AL = Static
01234 = Primary Key

syntax to create calculated column

ALTER TABLE [YourTable] ADD AutoCityCode AS ('PKR' + City + 'AL' + ID);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900