Solved

Select Distinct ColumnName From Table produces error I believe due to spaces, tabs or carriage returns

Posted on 2008-10-23
5
178 Views
Last Modified: 2013-12-17
I'm running a query against one of our tables.
Select Distinct ColumnName From Table. (SELECT DISTINCT FULLERROR
FROM [DMS].[dbo].[SD_LOGDATA])
When I run this command it produces the error "The text data type cannot be selected as DISTINCT because it is not comparable."
There are these funny looking squares in the FULLERROR Column and I believe these may be spaces, tabs or carriage returns.
Does anyone know what command I should run or if there's a way to change something up on the table to fix this?
Regards,
Wally
0
Comment
Question by:wally_davis
  • 2
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 250 total points
ID: 22790394
It's not due to the carriage returns.  It's due to the data type -- TEXT.

Are you allowed to change data types?  If so, change to Varchar(Max) -- new for SQL 2005.
0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 250 total points
ID: 22790449
OR... since changing the data type of a column can have massive ramifications, CAST the column in your select.

SELECT DISTINCT cast(FULLERROR as nvarchar(max))
FROM [DMS].[dbo].[SD_LOGDATA]
0
 

Author Comment

by:wally_davis
ID: 22790556
I used varchar in place of nvarchar(max)). So, yes we can change the datatype and we eventually will. both are great solutions and will award you each 250 points.
0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 250 total points
ID: 22790609
the problem with varchar is that varchar, without specifying a length, will default to 30.

So use varchar(max) instead of nvarchar(max) if you have a text column isntead of ntext.  But you should use max probably.  Why else would it be a TEXT column if it didn't house long data?
0
 

Author Closing Comment

by:wally_davis
ID: 31509412
Good point Brandon. Well, someone else on my team assigned Text datatype to this column that will hold a large amount of data when they should have assigned datatype varchar.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 r2 - Varible Table 3 24
.NET 2008 VB and C# 6 28
Can't disable touch pad on Windows 10 computer 16 33
MailAddress in vb 4 15
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question