I have an id field (int
type) and varchar
field.
I have to concatenate both columns and store the result to another column with data type nvarchar
;
Is this possible?
I have an id field (int
type) and varchar
field.
I have to concatenate both columns and store the result to another column with data type nvarchar
;
Is this possible?
Yes, of course:
UPDATE dbo.YourTable
SET NVarcharField = CAST(id AS NVARCHAR(10)) + CAST(VarCharField AS NVARCHAR(50))
WHERE (some condition)
You can create your new NVARCHAR column as computed one.
CREATE TABLE TestInsertComputedColumn
(
ID int,
Name VARCHAR(50)
);
insert into TestInsertComputedColumn(ID,Name)
select 8, 'vgv';
select * from TestInsertComputedColumn;
ALTER TABLE TestInsertComputedColumn
ADD FullName As Name + cast(id as nvarchar);
select * from TestInsertComputedColumn;
--drop TABLE TestInsertComputedColumn;