If you are using SQL Server 2005 or higher:
In the LEFT command, use CHARINDEX on CHAR (13) to find the position of the character of the first line, as in the following example:
declare @a table(id int identity(1,1) not null, lines text);
declare @b table(id int identity(1,1) not null, lines text);
insert into @a(lines) values ('1111111'+char(13)+char(10)+'222222')
insert into @b(lines) values ('aaaaa');
update b
set lines=LEFT(cast(a.lines as varchar(max)),CHARINDEX(char(13),cast(a.lines as varchar(max)),1)-1)+cast(b.lines as varchar(max))
from @a a
join @b b on a.id=b.id;
select * from @b;
I also suggest, if possible, updating TEXT data types to varchar (max). varchar (max) is much more reliable.
source
share