The field types of MSSQL sqlserver text and image cannot be shared with the processing method of distinct


Transferred from: 

The text image type in SQL Server database cannot be shared by distinct
Experimental environment: SQL Server 2017
In SQL server, we often need to take the distinct operation on a series of values, but when we directly do the distinct operation on the value of text type, there will be some error messages,
The following describes how to handle such exceptions so that the distinct keyword can be used, as follows:
Realization idea:
Convert text type to varchar (max)
Ntext type to nvarchar (max)
After the image type is converted to varchar (max), the distinct keyword is used

create table [](info text)
insert into [] values('sqlserver')
insert into [] values('maomao365') 
insert into [] values('SQL') 
Insert into [maomao365. Com] values (n 'database')

select distinct info from 
---Distinct transform data
select distinct convert(varchar(max),info)
from []
drop table []


Recommended Today Application of regular expression

1. Balanced group / recursive matching (?’ Group ‘), which is called the corresponding content of group, and counts it on the stack;(?’- Group ‘), and count the corresponding content named group out of the stack(?!) Zero width negative look ahead assertion. Since there is no suffix expression, attempts to match always failRegular example:,{0,1}”5″:\[[^\[\]]*(((?’Open’\[)[^\[\]]*)+((?’-Open’\])[^\[\]]*)+)*(?(Open)(?!))\],{0,1} Test […]