Reputation: 6610
I have an incremental field for each record in my table.
I want to add leading zeros to the number to make them all the same number of characters but also CAST() letters to the front of the number as an identifier.
Adding the leading zeros;
SELECT RIGHT('00000' + CONVERT(VARCHAR, No_), 6)
Adding my identifier;
SELECT 'FC' + CAST(No_ as varchar(50))
What is the correct syntax for combining these two statements to the one field? Is it possible?
Upvotes: 0
Views: 2847
Reputation: 24046
try
SELECT 'FC' +RIGHT('00000' + CONVERT(VARCHAR, No_ ), 6)
Result: For No_ = 1
FC000001
For No_ = 222
FC000222
Upvotes: 2
Reputation: 174329
Simply use this:
SELECT 'FC' + RIGHT('00000' + CONVERT(VARCHAR, No_), 6)
Upvotes: 1