How can I change NULL to 0 when getting a single value from a SQL function?

前端 未结 8 818
刺人心
刺人心 2021-02-06 20:02

I have a query that counts the price of all items between two dates. Here is the select statement:

SELECT SUM(Price) AS TotalPrice 
FROM Inventory
WHERE (DateAdd         


        
相关标签:
8条回答
  • 2021-02-06 21:00

    The easiest way to do this is just to add zero to your result.

    i.e.

    $A=($row['SUM'Price']+0);
    echo $A;
    

    hope this helps!!

    0 讨论(0)
  • 2021-02-06 21:02

    You can use ISNULL().

    SELECT ISNULL(SUM(Price), 0) AS TotalPrice 
    FROM Inventory
    WHERE (DateAdded BETWEEN @StartDate AND @EndDate)
    

    That should do the trick.

    0 讨论(0)
提交回复
热议问题