Solved

SQL Server Data type error

Posted on 2014-03-07
2
843 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
Comment Utility
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
Comment Utility
--
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

743 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

15 Experts available now in Live!

Get 1:1 Help Now