Reputation: 23
I have the following for adding a unique ID to the field in SQL 2014 Mgmt Studio
ADD MY_ID INT IDENTITY (1,1)
Is there a way where I can also append a fixed text next to the unique ID?
Problem lies where the column is set to INT to begin with so even if I add two columns where one is set as the ID and the other a set string, I can't concat it without a transformation.
In other words, can I do:
ADD MY_ID INT IDENTITY (1,1) + "Myfile.docx"
Thanks
Upvotes: 2
Views: 1194
Reputation: 12014
You can alter your table and add a computed column :
see this https://msdn.microsoft.com/en-us/library/ms188300.aspx
alter table dbo.MyTable
add MyComputedID as convert(varchar, my_id) + 'Myfile.docx'
or you can create a view :
create view dbo.vwMyTable as
select my_id,
foo1,
foo2,
...
convert(varchar, my_id) + 'Myfile.docx' as MyComputedID
from dbo.MyTable
Upvotes: 2