开发者

Concatenating String in SQL Server 2005

开发者 https://www.devze.com 2022-12-13 17:06 出处:网络
Does anyone know how I would go about concatenating a string in SQL Server 2005. What I mean is something like the following scenario.

Does anyone know how I would go about concatenating a string in SQL Server 2005.

What I mean is something like the following scenario.

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

Lets say the column has a value of "A" and I want to add "B" making "AB", what is the simplest way to go about 开发者_JAVA技巧this. Will I need to do a Select, concatenate the two values in code and then update the column? Or is there a more nifty way to do this?

Any pointers much appreciated.


In T-SQL:

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

If you were using Oracle it would be:

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消