Link to home
Start Free TrialLog in
Avatar of chrisryhal
chrisryhal

asked on

SQL Query Error Joining Tables

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

ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of chrisryhal
chrisryhal

ASKER

Awesome Thank You!