[RESOLVED] Save SP Result to Parameter
hi,
how do i save result to parameter when using SP?
i have something like this
Code:
SELECT SUM(price)
FROM employee
WHERE employee_id = @EmployeeID
the problem is that it sometimes return NULL, i want to save the result to parameter and check if this parameter is null if so i will return 0
something like that:
Code:
DECLARE @SumPrice decimal
SET @SumPrice = SELECT SUM(price)
FROM employee
WHERE employee_id = @EmployeeID IS NULL
i think i can do it like so...
Code:
IF SELECT SUM(price)
FROM employee
WHERE employee_id = @EmployeeID IS NULL
BEGIN
SELECT 0
END
ELSE
BEGIN
SELECT SUM(price)
FROM employee
WHERE employee_id = @EmployeeID IS NULL
END
but then i executing the query twice... (no good).... what is the best solution ?
thanks!
Re: Save SP Result to Parameter
What about this:
code Code:
SELECT ISNULL(SUM(price),0) As Summed
FROM employee
WHERE employee_id = @EmployeeID
Re: Save SP Result to Parameter
very nice, i never knew you can use isnull in such way.
Thanks!