Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Set null value from count result to 0 in SQL select
Sun, May 13 2018 4:52 AMPermanent Link

Mike

Hi,

I am using the following SQL statement as sub select.

SELECT COUNT(OrderID) AS MyCount FROM Jobs WHERE OrderID=Surprisedderid  AND OrderlineID > 0 AND status<>6 GROUP BY OrderID

How can I set the return value from count(orderid) to 0 when it is null?
Sun, May 13 2018 5:37 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Mike

Is the problem that you get some rows with a null or (as I'm guessing) that you get no rows?

Roy

Sun, May 13 2018 5:43 AMPermanent Link

Mike

Hi Roy,

I get some rows with a null. The null value must be set to 0.
Sun, May 13 2018 5:48 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Mike


Just looking at it again I think your problem will be solved if you just drop the GROUP BY clause. I'd also use COUNT(*)

SELECT COUNT(*) AS MyCount FROM Jobs WHERE OrderID=Surprisedderid  AND OrderlineID > 0 AND status<>6

You are picking a single OrderID so the GROUP BY is essentially grouping everything there anyway and isn't needed

Roy Lambert
Sun, May 13 2018 5:57 AMPermanent Link

Mike

Thank you!

That seems to do the trick.
Image