Unanswered: Help comparing '01234' with '1234' (with complications)
I have to join on two fields, both are of type char(8), but one is entered by the application so it maintains leading 0's while the other is hand entered, so there are no leading 0's (and we're never going to get our users to ALWAYS enter leading 0's).
So, since they're numbers anyway, I figured I would just convert them both to integers and join on that as in:
...CAST(ord_no1 as integer) = CAST(ord_no2 as integer)
Which works , BUT...
Since the ord_no field is actually a char(8) field, users can enter stuff other than numbers in it. Is there a way that I can use CAST as in the above, but let it ignore values that can not be converted? If it's not all numberals, it won't match anyway so I don't need to worry about them, however, when joining on that field, it has to look at all the records and perform the calculation and it's failing on a handful of them.
SET NOCOUNT OFF
CREATE TABLE myTable99(ord_no1 char(8), ord_no2 char(8))
INSERT INTO myTable99(ord_no1, ord_no2)
SELECT '01234','1234' UNION ALL
SELECT 'X1234','1234' UNION ALL
SELECT '6789','6789' UNION ALL
FROM ( SELECT *
WHERE ISNUMERIC(ord_no1) = 1 AND ISNUMERIC(ord_no2) = 1) AS XXX
WHERE CONVERT(int,ord_no1) = CONVERT(int,ord_no2)
WHERE (ISNUMERIC(ord_no1) = 0 OR ISNUMERIC(ord_no2) = 0)
AND ord_no1 = ord_no2
SET NOCOUNT OFF
DROP TABLE myTable99
I can't believe I'm doing this because I have a lot of issues with my accounting systems DB design, but it is in normal form.
When performing a warehouse transfer, a inventory issuance is entered for the warehouse the product is shipping from with ord_no = 1000 and doc_ord_no = 1000.
Then, an inventory receipt is entered for the warehouse the product is shipping to with ord_no = 1001 and doc_ord_no = 1000 which relates that receipt with the issuance.
I am trying to create a transfers report so I can list all the issuances and then do a join between ord_no and doc_ord_no (limiting the second table to only receipts) to show which transfers have arrived and which are in transit.