Solved

SQL Server Data type error

Posted on 2014-03-07
2
919 Views
Last Modified: 2014-03-07
Hi Experts,

I am facing an data type error while running below query. Please advise how to fix below error.

SELECT  Inquiries,[PO Number], max(Revision) AS MaxRevision
FROM [LinkedServer_1].[Database_1].dbo.CPOA  WITH(NOLOCK)
GROUP BY Inquiries ,[PO Number]

Error:
Msg 306, Level 16, State 2, Line 3
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

Data type:
---------
Inquiries varchar(max)
[PO Number] varchar(50)
Revision varchar(50)

Source server version:
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)   Jun 28 2012 08:36:30   Copyright (c) Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)

Destination version (lnked server version):
Microsoft SQL Server 2008 (SP3) - 10.0.5500.0 (X64)   Sep 21 2011 22:45:45   Copyright (c) 1988-2008 Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
0
Comment
Question by:sqldba2013
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
ID: 39911921
I think Inquiries field is having text datatype

work around for this

SELECT
CAST(Inquiries AS NVARCHAR(1000)) Inquiries
 ,[PO Number], max(Revision) AS MaxRevision
FROM [LinkedServer_1].[Database_1].dbo.CPOA  WITH(NOLOCK)
GROUP BY CAST(Inquiries AS NVARCHAR(1000))  ,[PO Number]
0
 

Author Closing Comment

by:sqldba2013
ID: 39912111
--
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

809 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