CREATE PROCEDURE cartTotal
(@CartID char(36), @gift smallint OUTPUT)
SELECT @gift = SUM(Quantity)
WHERE ShoppingCart.CartID = @CartID AND Gift = 1
Gift is a bit field. Quantity an int.
What I want to do is to total the Quantity field for every row where Gift = 1.
1 3 so in this case @gift would equal 4.
I tried the above but get an error:
System.InvalidCastException: Cast from type 'DBNull' to type 'Short' is not valid
details.gift = CType(command.Parameters("@gift").Value, Short)
But this line works in above: SELECT @gift = count(*) . . . but I need to add the
Quantity to the count for every row where Gift = 1.