I have the following sql function, but not running correctly, the intended returned value is the total
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create FUNCTION [dbo].[SumIf](@ColumnName [varchar](100), @Criteria [varchar](500))
RETURNS [decimal] AS
BEGIN
-- Declare the return variable here
DECLARE @Total Decimal
DECLARE @TableName Decimal
Select @Total = SUM(@ColumnName) from @TableName where @Criteria
RETURN @Total
END
the use syntax would be something like
Select dbo.sumif(fees.fee_amount, Fees.Fee_Code ='B01')
So the tablename would also need to be extracted from the columnname variable passed.