Hello,
First of all i would say that you did a big mistake while creating table design for this. You should have added one column which stores the above Code in given format .Now you have to write this logic all over the database where you want to access "account no" which is a tiresome job. If you simple add one column in table "t_customer_account ". Still its not late to do so.Add one column and write a procedure which will update each record and will create Account No and update it back to record. And modify the logic to insert record for this code.
Do you have any idea how much Processing speed you are wasting on the cost of Memory?
Another thing, Use
RIGHT ('000'+ CAST ( CompanyCode AS varchar), 3) AS CompanyCode
This will automatically insert 0's in right if Code is like 99 it will be 099 afterwards. You don't need to check length and have to write logic for this.
Could you please send your table structure here