UPDATE rptMaster SET
nQtyOnHand = (select (QTYONHND / rptMaster.UOMQTY) from itemMaster
where LOCNCODE = '001' and
itemMaster.ITEMNMBR = CASE
WHEN rptMaster.ITEMNMBR like '%P'
THEN SUBSTRING(rptMaster.ITEMNMBR, 1, DATALENGTH(rptMaster.ITEMNMBR) - 1)
ELSE rptMaster.ITEMNMBR
END)
What's wrong with the above query. It is inside sql stored procedure. But I don't see the condition getting executed. I am checking if the itemnumber ends with 'P', then I want to ignore the 'P'. The table has records with itemnumber without ending in 'P' as well as ending in 'P'.
Earlier the query was something like below, which worked fine.
UPDATE rptMaster SET
nQtyOnHand = (select (QTYONHND / rptMaster.UOMQTY) from itemmaster
where LOCNCODE = '001' and
itemmaster.ITEMNMBR = rptMaster.ITEMNMBR)