Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-23
5
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 1000 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 1000 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 1000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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