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

Time:2021-2-18

Transferred from: http://www.maomao365.com/?p=9775 

Abstract:
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 [maomao365.com](info text)
insert into [maomao365.com] values('sqlserver')
insert into [maomao365.com] values('maomao365') 
insert into [maomao365.com] values('SQL') 
Insert into [maomao365. Com] values (n 'database')
go

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

 

Recommended Today

asp.net 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 […]