This question is difficult to word, so I will do my best to be thorough.
Here is a bit of information to start. This query:
SELECT PART.ID, REQUIREMENT.WORKORDER_TYPE
, REQUIREMENT.WORKORDER_BASE
_ID, PART.AUTO_BACKFLUSH, PART.PRODUCT_CODE,
REQUIREMENT.USER_10, REQUIREMENT.ISSUED_QTY
FROM PART INNER JOIN
REQUIREMENT ON PART.ID = REQUIREMENT.PART_ID
WHERE (REQUIREMENT.WORKORDER_TYP
E = 'W') AND (PART.PRODUCT_CODE = 'SA31') AND (PART.AUTO_BACKFLUSH = 'N') AND
(REQUIREMENT.USER_10 = 'Y')
ORDER BY REQUIREMENT.WORKORDER_BASE
_ID
Returns no results because there are no Y's in the USER_10 column. If I change the requirement so that I am looking for an AUTO_BACKFLUSH = 'Y', then in that case there are Y's in the USER_10 Column. Fortunately for me, I am only interested in non-autobackflush parts, thus negating the possibility of a Y in USER_10.
That was long winded. Now, I take:
SELECT PART.ID, REQUIREMENT.WORKORDER_TYPE
, REQUIREMENT.WORKORDER_BASE
_ID, PART.AUTO_BACKFLUSH, PART.PRODUCT_CODE,
REQUIREMENT.USER_10, REQUIREMENT.ISSUED_QTY
FROM PART INNER JOIN
REQUIREMENT ON PART.ID = REQUIREMENT.PART_ID
WHERE (REQUIREMENT.WORKORDER_TYP
E = 'W') AND (PART.PRODUCT_CODE = 'SA31') AND (PART.AUTO_BACKFLUSH = 'N') AND
(REQUIREMENT.ISSUED_QTY > REQUIREMENT.USER_10)
ORDER BY REQUIREMENT.WORKORDER_BASE
_ID
And SQL 2000 tells me that it cannot assign a varchar column to a numeric column. I know this, so I then add in the cast function:
SELECT PART.ID, REQUIREMENT.WORKORDER_TYPE
, REQUIREMENT.WORKORDER_BASE
_ID, PART.AUTO_BACKFLUSH, PART.PRODUCT_CODE,
REQUIREMENT.USER_10, REQUIREMENT.ISSUED_QTY
FROM PART INNER JOIN
REQUIREMENT ON PART.ID = REQUIREMENT.PART_ID
WHERE (REQUIREMENT.WORKORDER_TYP
E = 'W') AND (PART.PRODUCT_CODE = 'SA31') AND (PART.AUTO_BACKFLUSH = 'N') AND
(REQUIREMENT.ISSUED_QTY > cast(REQUIREMENT.USER_10 as int))
ORDER BY REQUIREMENT.WORKORDER_BASE
_ID
Furthermore, if there are any <NULL> values in this column, I want to change them to zero as such:
SELECT PART.ID, REQUIREMENT.WORKORDER_TYPE
, REQUIREMENT.WORKORDER_BASE
_ID, PART.AUTO_BACKFLUSH, PART.PRODUCT_CODE,
REQUIREMENT.USER_10, REQUIREMENT.ISSUED_QTY
FROM PART INNER JOIN
REQUIREMENT ON PART.ID = REQUIREMENT.PART_ID
WHERE (REQUIREMENT.WORKORDER_TYP
E = 'W') AND (PART.PRODUCT_CODE = 'SA31') AND (PART.AUTO_BACKFLUSH = 'N') AND
(REQUIREMENT.ISSUED_QTY > cast(isnull(REQUIREMENT.US
ER_10,'0')
as int))
ORDER BY REQUIREMENT.WORKORDER_BASE
_ID
Beautiful. There is a problem, though, and this is where I need help. SQL 2000 now tells me:
"Syntax error converting the varchar value 'Y' to a column of data type int."
But wait, there aren't any Y's in this select statement! I have a feeling this is going to be one of those "You idiot!" solutions that just needs a fresh set of eyes. This would be easier if you had the data to work with, and for that I apologize. I should mention that I get the same result whether I use cast or convert, isnull or coalesce. Thanks in advance for your help!