String Concatenation in SQL Server 2005

Does anyone know how I was going to concatenate a row in SQL Server 2005.

I mean something like the following scenario.

I have an nvarchar (MAX) column in a SQL Server 2005 database.

Let's say that the column has a value of “A” and I want to add “B”, which makes “AB”, which is the easiest way to do this. Do I need to make a selection, combine the two values ​​in the code and then update the column? Or is there a better way to do this?

Any pointers are greatly appreciated.

+3
source share
2 answers

In T-SQL:

     UPDATE table SET col = col + 'B' WHERE (PREDICATE THAT IDENTIFIES ROW)

If you used Oracle, this would be:

     UPDATE table SET col = col || 'B' WHERE (PREDICATE THAT IDENTIFIES ROW)
+7
source

You can do something like this

DECLARE @Table TABLE(
        Col VARCHAR(MAX)
)

INSERT INTO @Table (Col) SELECT 'A'

SELECT  Col + 'B'
FROM    @Table

UPDATE @Table
SET Col = Col + 'B'

SELECT * FROM @Table
+2

Source: https://habr.com/ru/post/1724703/


All Articles