Question

Basically, I'm trying to convert a table field while doing a join. The numbers in a field starts with 0009897896, 000239472938, 00032423, and so forth.

I want to do a join based convert, so when I query the column, it will display the numbers without the leading 0s, so they would display like 9897896, 239472938, 32423 and so forth.

Can someone help me avchieve this? I've been stuck on this issue for awhile :(

Here's what I've got so far... joining from a different database:

SELECT l.loannumber AS '1 Loan number',
       fl.loan_num AS '2 Loan number',
       CASE
           WHEN loannumber<>fl.loan_num THEN "YES"
           ELSE "NO"
       END AS "issue?"
FROM loan l
LEFT JOIN cware_cms.file_lst fl ON (CONVERT(SUBSTRING_INDEX(l.LoanNumber, '-', -1), UNSIGNED INTEGER)) = (CONVERT(SUBSTRING_INDEX(fl.loan_num, '-', -1),UNSIGNED INTEGER))
LEFT JOIN cware_cms.case_lst cl ON cl.case_id =
  (SELECT MAX(cware_cms.file_case.case_id))
FROM cware_cms.file_case
INNER JOIN cware_cms.case_lst ON cware_cms.file_case.case_id = cware_cms.case_lst.case_id
Was it helpful?

Solution

I think you want to TRIM LEADING zeros. This will do the trick:

LEFT JOIN cware_cms.file_lst fl ON TRIM(LEADING '0' FROM l.loannumber) = TRIM(LEADING '0' FROM fl.loan_num)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top