SQL Server - Adding a string to a text column (concat equivalent)

后端 未结 6 1645
一整个雨季
一整个雨季 2021-02-03 20:21

How do you add a string to a column in SQL Server?

UPDATE [myTable] SET [myText]=\' \'+[myText]

That doesn\'t work:

The

6条回答
  •  既然无缘
    2021-02-03 20:53

    The + (String Concatenation) does not work on SQL Server for the image, ntext, or text data types.

    In fact, image, ntext, and text are all deprecated.

    ntext, text, and image data types will be removed in a future version of MicrosoftSQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

    That said if you are using an older version of SQL Server than you want to use UPDATETEXT to perform your concatenation. Which Colin Stasiuk gives a good example of in his blog post String Concatenation on a text column (SQL 2000 vs SQL 2005+).

提交回复
热议问题