Automatically CONCATENATE text on data entry
- by Bill T
I am a newbie and need help.
I have a table called "Employees". It has 2 fields [number] and [encode]. I want to automatically take whatever number is entered into [number] and store it in [encode] so that it is preceded by the appropriate amount of 0's to always make 12 digits.
Example:
user enters '123' into [number], '000000000123' is automatically stored in [encode]
user enters '123456789' into [number], '000123456789' is automatically stored in [encode]
I think i want to write a trigger to accomplish this. I think that would make it happen at the time of data entry. is that right?
The main idea is would be something like this:
variable1 = LENGTH [number]
variable2 = REPEAT (0,12-variable1)
variable3 = CONCATENATE (variable2, [number])
[encode] = variable3
I just don't know enough to make this happen
ANY help would be FANTASTIC.
I have SQL-SERVER 2005 and both fields are text