How to sort the TEXT data type
Essentially, we cannot use the ORDER BY clause on text, unitext, or image datatype columns. However we can SORT the TEXT by converting it to VARCHAR/CHAR.
Example:
create table JobDetails ( JobId int, JobName char, JobDescr text ) insert into JobDetails values (1,'AAA','This Stored Procedure clears all input tables') insert into JobDetails values (2,'BBB','Get the Processing date corresponding to the current data') insert into JobDetails values (3,'CCC','This SP clears up the work tables so that fresh data can be loaded for the processing days processing') insert into JobDetails values (4,'DDD','Stored Procedure inserts the statistics for the existing records for which data is received at the same day') insert into JobDetails values (5,'EEE','This Stored Procedure clears all input tables') insert into JobDetails values (6,'FFF','Get the Processing date corresponding to the current data')
Select * from JobDetails order by JobDescr ? This query will not execute
Solution: We have to convert the “TEXT” data type to VARCHAR/CHAR to sort it
Select * from JobDetails order by convert(varchar(1200),JobDescr)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|