Reputation: 51
I have an Access DB that contains the following column/fields: [ID], [itemCode], [imageCode].
The fileCode is "computed" expression of:
[itemCode] & "IMG" & [ID] & ".jpg"
So that if [ID] and [itemCode] are "4" and "item008a" (respectively) then the [imageCode] will be: "item008aIMG4.jpg".
However, I am migrating to SQL, and while rebuilding the table, I found you can't do this with the column's default value or computed formula.
I've read triggers would be the best resolve, but have only written triggers that affect other tables and not itself (if that is even possible?).
Is there something more direct? If not, what would the trigger look like?
Any help most appreciated. Thanks.
Upvotes: 0
Views: 36
Reputation: 13425
You can add it as computed column
ALTER Table TableA ADD imageCode
AS cast(itemCode as varchar(10))
+ 'IMG' + cast( id as varchar(10))
+ '.jpg'
Upvotes: 2