Reputation: 14448
I have a table that has several columns of textual data. The goal is to concatenate those columns into a single different column in the same table and same row.
What is the SQL Server query syntax that would allow me to do this?
Upvotes: 4
Views: 9542
Reputation: 16240
Do you absolutely have to duplicate your data? If one of the column values changes, you will have to update the concatenated value.
A computed column:
alter table dbo.MyTable add ConcatenatedColumn = ColumnA + ColumnB
Or a view:
create view dbo.MyView as
select ColumnA, ColumnB, ColumnA + ColumnB as 'ConcatenatedColumn'
from dbo.MyTable
Now you can update ColumnA or ColumnB, and ConcatenatedColumn will always be in sync. If that's the behaviour you need, of course.
Upvotes: 3
Reputation: 5648
Might be misunderstanding but:
Alter table myTable add combinedColumn Varchar(1000);
Update myTable set combinedColumn = textField1 + textField2;
Upvotes: 1
Reputation: 10517
select
textfield1 + textfield2 + ... + textfieldN as conc_text,
otherfield1,
otherfield2,
...
otherfieldN
from
mytable
Upvotes: 0