CREATE FUNCTION dbo.CalcSum (@input VARCHAR(50))
RETURNS VARCHAR(50)
AS BEGIN
DECLARE @result VARCHAR(50)
SELECT @result=sum(Sales_Invoice.grand_total) FROM Sales_Invoice
RETURN @result
END
and use
select dbo.CalcSum(Sales_Invoice.grand_total) from Sales_Invoice
Member
49 Points
154 Posts
calling function in select statement in sql
Aug 27, 2018 07:38 AM|chnar|LINK
i want to create this query as function and then calling in in another query inside select statement
SELECT sum(Sales_Invoice.grand_total) FROM Sales_Invoice
Star
8119 Points
2778 Posts
Re: calling function in select statement in sql
Aug 27, 2018 07:48 AM|vahid bakkhi|LINK
hi
you can try below
and use
Please MARK AS ANSWER if suggestion helps.
Member
49 Points
154 Posts
Re: calling function in select statement in sql
Aug 27, 2018 08:05 AM|chnar|LINK
i have this error
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.CalcSum", or the name is ambiguous.
Star
8119 Points
2778 Posts
Re: calling function in select statement in sql
Aug 27, 2018 08:46 AM|vahid bakkhi|LINK
First, make sure you did run the create script in the correct database.
Second, as @input VARCHAR(50) started mentioning, you are using the function results incorrectly.
Please MARK AS ANSWER if suggestion helps.