Solved

SQL Server Data type error

Posted on 2014-03-07
2
897 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

920 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

14 Experts available now in Live!

Get 1:1 Help Now