Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQLServer type text operator is not compatible

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

SQLServer type text operator is not compatible

DB: SQLServer 2012

Question:

Columns of type Text, the "=" operator is not supported.

The error is as follows:

Message 402, level 16, status 1, line 1

The data types text and varchar are not compatible in the equal to operator.

Problem phenomenon:

-create table test0706 (id int,a text)

-insert into test0706 select id,ssfb as a from T1

Select * from test0706 where axioms 10'

Message 402, level 16, status 1, line 1

The data types text and varchar are not compatible in the equal to operator.

Select * from test0706 where an in ('10')

Message 402, level 16, status 1, line 1

The data types text and varchar are not compatible in the equal to operator.

Update test0706 set axiom 100 where id='2'

Message 206, level 16, status 2, line 1

Operand type conflict: int is not compatible with text

Solution:

One: like

Text type query does not support =, but can support like

Select * from test0706 where a like '10'

Two: cast

Select * from test0706 where cast (an as nvarchar) = '10'

-similarly, it can also be used for update.

BEGIN TRAN

Update test0706 set a = cast ('100' as text) where id=2

COMMIT TRAN

-ROLLBACK TRAN

Three: READTEXT (Transact-SQL)

Https://docs.microsoft.com/zh-cn/previous-versions/sql/sql-server-2008-r2/ms187365(v=sql.105)

Reads the text, ntext, or image value from a text, ntext, or image column, and reads the specified number of bytes starting at the specified offset.

Syntax:

READTEXT {table.column text_ptr offset size} [HOLDLOCK]

……

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report