Google Analytics İzleme

23 Eylül 2011

SQL Server - Operand data type ntext is invalid for add operator. hatası hakkında

Bu hata sql server ile text veya ntext veri tipi ile işlem yapınca çıkmaktadır.

Örneğin:
select
 cast(A.AnswerText as ntext) + cast(' - ' as ntext) + cast(VA.AnswerText as ntext)
from
 vts_tbAnswer A join vts_tbVoterAnswers VA on A.AnswerID = VA.AnswerID

Yukarıdaki sql sorgusunda bu hatayı vermektedir.
Artık SQL Server text ve ntext kullanımını desteklemeyecekmiş, bunun yerine varchar(max) veya nvarchar(max) kullanmamızı istiyor.


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+).

 

Kaynak:

http://msdn.microsoft.com/en-us/library/ms187993.aspx


http://stackoverflow.com/questions/3099237/sql-server-adding-a-string-to-a-text-column-concat-equivalent




Hiç yorum yok: