case when PartPlant.MMSHistory = 0 then ceiling (case when (sum(orderdtl.SellingQuantity/12) < 3 or sum(orderdtl.SellingQuantity) is null then 6 else (sum(orderdtl.SellingQuantity)/12) end)
else ceiling (case when (sum(orderdtl.SellingQuantity)/12) < 3 or sum(orderdtl.SellingQuantity) is null then 3 else (sum(orderdtl.SellingQuantity)/12) end
And when i hit check syntax it says: Incorrect syntax near the keyword ‘then’ Except nothing looks out of place. Since I’m going cross eyed, I thought I’d see if a fresh pair of eyes would help me.
case when PartPlant.MMSHistory = 0 then ceiling (case when (sum(orderdtl.SellingQuantity)/12) < 3 or sum(orderdtl.SellingQuantity) is null then 6 else (sum(orderdtl.SellingQuantity)/12) end)
else ceiling (case when (sum(OrderDtl.sellingSellingQuantity)/12) < 3 or sum(OrderDtl.SellingQuantity) is null then 3 else (sum(OrderDtl.SellingQuantity)/12) end
But It now says Incorrect Syntax near ‘Calcualted_SuggetedMin.’
And here is the winner!
One paren and another End.
case when PartPlant.MMSHistory = 0 then ceiling (case when (sum(orderdtl.SellingQuantity)/12) < 3 or sum(orderdtl.SellingQuantity) is null then 6 else (sum(orderdtl.SellingQuantity)/12) end)
else ceiling (case when (sum(OrderDtl.SellingQuantity)/12) < 3 or (sum(OrderDtl.SellingQuantity)/12) is null then 3 else (sum(OrderDtl.SellingQuantity)/12) end) end
When I get stuck with these, I find the best way to copy into SSMS (or notepad++ and set the language to SQL) and then reformat it like the following as it’s easy to figure out what’s missing:
-------------------------------
case when PartPlant.MMSHistory = 0
then ceiling
(
case when (sum(orderdtl.SellingQuantity/12) < 3
or sum(orderdtl.SellingQuantity) is null
then 6
else (sum(orderdtl.SellingQuantity)/12)
end
)
else ceiling
(
case when (sum(orderdtl.SellingQuantity)/12) < 3
or sum(orderdtl.SellingQuantity) is null
then 3
else (sum(orderdtl.SellingQuantity)/12)
end
-------------------------------
From here it’s easy to see that there is a missing a closing parentheses in the second case and missing end and closing parentheses to the last case.