Solved

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

Posted on 2008-10-23
5
173 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now