adam2804
Posts: 34 Joined: 6/6/2006 Status: offline
|
SQL query problem - 6/29/2006 11:05:39
Any takers to this one? It's doing my head in
SELECT w.WorkType, t.Description, p.Unit, CAST(ROUND(p.Price, 2) AS MONEY) AS Price, CONVERT(CHAR, CEILING
((SELECT SUM(Quantity)
FROM WorkDetails W
WHERE JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType)))) AS Quantity, CONVERT(VARCHAR, CAST
((SELECT SUM(Hours)
FROM WorkDetails W
WHERE JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType)) / 24 AS DATETIME), 108) AS Hours, CONVERT(CHAR,
CAST((b.QuantityMultiplier *
(SELECT SUM(Quantity)
FROM WorkDetails W
WHERE JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType)) + b.TimeMultiplier *
(SELECT SUM(Hours)
FROM WorkDetails W
WHERE JobNumber = P.ID AND W.WorkType = ISNULL(P.BillUsing, P.WorkType))) * p.Price / p.Unit AS MONEY)) AS TotalPrice,
b.Description AS Billing, p.ID, p.BillUsing
FROM WorkDetails w INNER JOIN
TB_MasterPrices p ON w.JobNumber = p.ID AND w.WorkType = p.WorkType INNER JOIN
WorkType t ON p.WorkType = t.WorkType INNER JOIN
TB_Billing b ON p.Billing_ID = b.ID
WHERE (w.JobNumber = '58610')
GROUP BY w.WorkType, t.Description, p.Unit, p.Price, b.Description, p.ID, p.BillUsing, p.WorkType, b.TimeMultiplier, b.QuantityMultiplier, p.ID, w.JobNumber
The problem I'm having is with the Quantity, Hours & TotalPrice columns where the resulting table doesn't work if there is a null result. However, it should work. Anything that looks obviously wrong?
|