Last post Aug 27, 2018 08:46 AM by vahid bakkhi
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
Aug 27, 2018 07:48 AM|vahid bakkhi|LINK
you can try below
CREATE FUNCTION dbo.CalcSum (@input VARCHAR(50))
DECLARE @result VARCHAR(50)
SELECT @result=sum(Sales_Invoice.grand_total) FROM Sales_Invoice
select dbo.CalcSum(Sales_Invoice.grand_total) from Sales_Invoice
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.
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.