Требуется помощь для устранения ошибки: сообщение 8114, уровень 16, состояние 5, строка 2 Ошибка преобразования типа данных varchar в числовой.
CASE WHEN (proj.UserText1 IS NULL OR proj.UserText1 = '')
THEN 0.00
ELSE
CASE
WHEN sopHdr.SOPTYPE = 4
THEN (((sopHdr.DOCAMNT - inv.TaxTotal) - inv.CostTotal) * - 1) * (proj.UserText1 / 100.0)
ELSE ((sopHdr.DOCAMNT - inv.TaxTotal) - inv.CostTotal) * (proj.UserText1 / 100.0)
END
END AS [Accrued Commission],
CASE WHEN (sopHdr.DOCAMNT < 0) OR (sopHdr.SOPTYPE = 4 AND sopHdr.DOCAMNT > 0) THEN 100.00
ELSE
CASE WHEN (Paid.Paid IS NULL OR Paid.Paid = 0) OR (sopHdr.DOCAMNT = 0 OR sopHdr.DOCAMNT IS NULL) THEN 0.00
ELSE (Paid.Paid / sopHdr.DOCAMNT) * 100
END END AS [Paid %],
CASE WHEN sopHdr.DOCAMNT < 0 THEN (sopHdr.DOCAMNT)
WHEN (sopHdr.SOPTYPE = 4 AND sopHdr.DOCAMNT > 0) THEN (sopHdr.DOCAMNT * - 1)
ELSE CASE WHEN Paid.Paid IS NULL THEN 0.00
ELSE Paid.Paid
END END AS [Amount Received],
CASE WHEN sopHdr.SOPTYPE = 4
THEN (inv.TaxTotal * - 1)
ELSE inv.TaxTotal
END AS [Tax Amount],
CASE WHEN sopHdr.SOPTYPE = 4 THEN CAST(CAST(((sopHdr.SUBTOTAL - inv.TaxTotal - inv.CostTotal) * - 1) AS DECIMAL(13,6)) as float)
ELSE CAST(CAST((sopHdr.SUBTOTAL - inv.TaxTotal - inv.CostTotal)AS DECIMAL(13,6)) as float)
END AS [Gross Profit],
CASE WHEN sopHdr.SOPTYPE = 4 THEN (inv.CostTotal * - 1)
ELSE inv.CostTotal
END AS [Ext Cost],
CASE WHEN (proj.UserText1 IS NULL OR proj.UserText1 = '') THEN CAST('0.00' as varchar)
ELSE CAST(proj.UserText1 as varchar)
END AS [Commission %],
CASE WHEN sopHdr.SOPTYPE = 4 THEN CAST(CAST(((sopHdr.DOCAMNT - inv.TaxTotal) * - 1) AS DECIMAL(13,6)) as float)
ELSE CAST(CAST((sopHdr.DOCAMNT - inv.TaxTotal) AS DECIMAL(13,6)) as float)
END AS [Net Sales],
И ошибка:
Сообщение 8134, уровень 16, состояние 1, строка 16
Ошибка деления на ноль.
Case#9
CASE WHEN (sopHdr.SUBTOTAL IS NULL OR sopHdr.SUBTOTAL = 0) THEN 0.00
ELSE
CASE WHEN sopHdr.SOPTYPE = 4 THEN ((sopHdr.SUBTOTAL - inv.TaxTotal - inv.CostTotal) /(sopHdr.SUBTOTAL) - (inv.TaxTotal)) * - 100
ELSE (((sopHdr.SUBTOTAL - inv.TaxTotal - inv.CostTotal) / (sopHdr.SUBTOTAL) - (inv.TaxTotal)) * 100)
END
END AS [Sale Gross Profit %],
Пожалуйста, сообщите.Спасибо