?
Solved

SQL 2005 - The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

Posted on 2010-09-23
2
Medium Priority
?
671 Views
Last Modified: 2012-05-10
Please note, the SQL is handled dynamically by the SQL server, therefore items in my WHERE clause will look odd to you. Please disregard this because this is not an issue.

I am getting the following error I need some help with.

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

SET NOCOUNT ON

SELECT     
	Batch.Entry AS [Date Of Entry], 
	PatientProfile.[Last] + ', ' + PatientProfile.[First] AS Name, 
	dbo.FormatName(Guarantor.Prefix, Guarantor.First, Guarantor.Middle, Guarantor.Last, Guarantor.Suffix) AS [Guarantor],
	MedLists.Description AS [Adjustment Type], 
	ISNULL(vo.Description, 'No Owner') AS [Visit Owner],
	PatientVisit.TicketNumber, 
--	PatientVisitProcs.Code AS [Procedure Code], 
	SUM(TransactionDistributions.Amount) AS [Adjustment Amount], 
	PatientVisitProcs.DateOfServiceFrom, 
	ISNULL(CONVERT(varchar(255), Transactions.Note), ' ') AS Notes, 
	CASE WHEN 1 = 1 THEN ISNULL(ml.Description,ISNULL(ic.ListName,'No Insurance')) ELSE ISNULL(ic.ListName,'No Insurance') END AS InsuranceType

FROM         
	PaymentMethod 
	INNER JOIN VisitTransactions ON PaymentMethod.PaymentMethodId = VisitTransactions.PaymentMethodId 
	INNER JOIN Transactions ON VisitTransactions.VisitTransactionsId = Transactions.VisitTransactionsId 
	INNER JOIN TransactionDistributions ON Transactions.TransactionsId = TransactionDistributions.TransactionsId 
	INNER JOIN Batch ON PaymentMethod.BatchId = Batch.BatchId 
	INNER JOIN PatientVisit ON VisitTransactions.PatientVisitid = PatientVisit.PatientVisitId 
	INNER JOIN PatientProfile ON PatientVisit.PatientProfileId = PatientProfile.PatientProfileId 
	INNER JOIN Guarantor ON PatientProfile.GuarantorId = Guarantor.GuarantorId
	INNER JOIN MedLists ON Transactions.ActionTypeMId = MedLists.MedListsId 
	INNER JOIN PatientVisitProcs ON TransactionDistributions.PatientVisitProcsId = PatientVisitProcs.PatientVisitProcsId 
	LEFT OUTER JOIN InsuranceCarriers ic ON CASE WHEN 1 = 1 THEN PatientVisit.PrimaryInsuranceCarriersID ELSE VisitTransactions.InsuranceCarriersID END = ic.InsuranceCarriersID 
	LEFT OUTER JOIN MedLists ml ON ic.PolicyTypeMID = ml.MedListsID
	LEFT OUTER JOIN MedLists vo ON PatientVisit.VisitOwnerMID = vo.MedListsID

WHERE     
	Transactions.Type = 'A'
	AND --Filter on Source of Adjustment
	(
	('3' = PaymentMethod.Source)  OR
	('3' = '3')
	)
	AND  --Filter on adjustment type
	(
	(1 = 2 AND Transactions.ActionTypeMId IN (NULL)) OR
	(1 = 1)
	)
	AND  --Filter on doctor
	(
	(NULL IS NOT NULL AND PatientVisit.DoctorID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on facility
	(
	(NULL IS NOT NULL AND PatientVisit.FacilityID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND  --Filter on company
	(
	(NULL IS NOT NULL AND PatientVisit.CompanyID IN (NULL)) OR
	(NULL IS NULL)
	)
	AND -- Filter on Guarantor
	( 
	('656' IS NOT NULL AND Guarantor.GuarantorId IN(656)) 
 	OR '656' IS NULL 
	)
	AND  --Filter on Visit Owner
	(
	(1 = 2 AND PatientVisit.VisitOwnerMID IN (NULL)) OR
	(1 = 1)
	)
	AND  --Filter on date range
	(
	(1 = 1 AND Batch.Entry >= ISNULL(NULL, '1/1/1900') AND Batch.Entry < 
    DATEADD(d,1,ISNULL(NULL,'1/1/3000'))) OR
	(1 <> 1 AND PaymentMethod.DepositDate >= ISNULL(NULL, '1/1/1900') AND PaymentMethod.DepositDate <                 
	DATEADD(d,1,ISNULL(NULL,'1/1/3000')))
	)
	AND  --Filter on procedures
	(
	(NULL IS NOT NULL AND PatientVisitProcs.ProceduresId IN (NULL)) OR
	(NULL IS NULL)
	) 
	AND  --Filter on Insurance Carrier
	(
	(NULL IS NOT NULL AND CASE WHEN 1 = 1 THEN PatientVisit.PrimaryInsuranceCarriersID ELSE VisitTransactions.InsuranceCarriersID END IN (NULL)) 	OR
	(NULL IS NULL)
	)
	
GROUP BY
	Batch.Entry,
	PatientProfile.Last,
	PatientProfile.First,
	Guarantor.Prefix,
	Guarantor.First,
	Guarantor.Middle,
	Guarantor.Last,
	Guarantor.Suffix,
	MedLists.Description,
	ISNULL(vo.Description, 'No Owner'),
	PatientVisit.TicketNumber,
	PatientVisitProcs.DateOfServiceFrom,
	Transactions.Note

ORDER BY PatientProfile.[Last] + ', ' + PatientProfile.[First], PatientVisitProcs.DateOfServiceFrom

Open in new window

0
Comment
Question by:Jeff S
[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 Comments
 
LVL 7

Accepted Solution

by:
mmr159 earned 2000 total points
ID: 33746035
I don't know what variable you are using but, ou cannot GROUP BY on on TEXT, NTEXT.

To get around this, you can CAST your TEXT, NTEXT types to VARCHAR in the GROUP BY.
0
 
LVL 7

Author Closing Comment

by:Jeff S
ID: 33746184
Thanks.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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. …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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