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

x
?
Solved

SQL Query Error Joining Tables

Posted on 2009-07-16
3
Medium Priority
?
181 Views
Last Modified: 2012-05-07
The below query I was hoping would ONLY show me criteria if for starters part.character03 = 'Package' along with other criteria, yet it still shows me values within Character03 that are OTHER THAN "Package"

I tried part.character03 = 'PACKAGE' and I get an errors saying:  The data types text and varchar are incompatible in the equal to operator.

Any help is appreciated
SELECT     part.partnum, part.character03, shipdtl.packnum
FROM         shipdtl INNER JOIN
                      part ON shipdtl.partnum = part.partnum
WHERE     (part.character03 LIKE 'PACKAGE') AND (shipdtl.packnum = 221) OR
                      (shipdtl.packnum = 222) OR
                      (shipdtl.packnum = 224)

Open in new window

0
Comment
Question by:chrisryhal
[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
3 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 2000 total points
ID: 24869030
What about this?
SELECT  part.partnum, 
	part.character03, 
	shipdtl.packnum
FROM    shipdtl 
INNER JOIN part ON shipdtl.partnum = part.partnum
WHERE     (part.character03 LIKE 'PACKAGE') AND (shipdtl.packnum in (221, 222, 224))

Open in new window

0
 
LVL 41

Expert Comment

by:ralmada
ID: 24869060
Btw, From books online, index entry Boolean expressions:

"Comparison operators test whether two expressions are the same. Comparison operators can be used on all expressions except expressions of the text, ntext, or image data types. "

If your character03 column is always (or even usually) under 8000 characters, you might consider to change to a varchar type.  Or you might want to implement two columns, one a smaller description, the other a text column that has long values.  Using the current column.

If not, then you will have to use LIKE or PATINDEX, or cast the values to a varchar (perhaps in a computed column) if you need to do this frequently and not on a really large value.
0
 
LVL 2

Author Closing Comment

by:chrisryhal
ID: 31604217
Awesome Thank You!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 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