The operator is invalid for data types. The operator is add and the type is text.

Source: Internet
Author: User

Recently, when developing a file management system, I encountered another problem: the local database was originally sql2008, And the shareduserid field was nvarchar (max) type, I used the SQL query statement... where shareduserid + ',' like '% 2, %', can be executed normally. LaterProgramReleased to the purchased space server. The server is the SQL2000 database. Because SQL2000 does not have the nvarchar (max) type, it is changed to the text type, the program reports an error when executing the same SQL statement:

---------------------------
Microsoft Internet Explorer
---------------------------
The operator is invalid for data types. The operator is add and the type is text. (System. Exception)
---------------------------
OK
---------------------------

So I changed the field type of the local database to text, and then tested it. A similar error was reported (even sql2008 is in English ):

---------------------------
Microsoft Internet Explorer
---------------------------
The data types text and varchar are incompatible in the Add operator. (system. Exception)
---------------------------
OK
---------------------------

after searching online, the original query statement is slightly modified (convert text to nvarchar and then execute the + operation): ... where shareduserid + ',' like '% 2, %' to ... where cast (shareduserid as nvarchar) + ', 'like' % 2, %' or where convert (nvarchar, shareduserid) + ', 'like' % 2, % '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.