sql server - SQL Function for SumIf 2012 -
this question has answer here:
i have following sql function, not running correctly, intended returned value total
set ansi_nulls on go set quoted_identifier on go create function [dbo].[sumif](@columnname [varchar](100), @criteria [varchar](500)) returns [decimal] begin -- declare return variable here declare @total decimal declare @tablename decimal select @total = sum(@columnname) @tablename @criteria return @total end
the use syntax like
select dbo.sumif(fees.fee_amount, fees.fee_code ='b01')
so tablename need extracted columnname variable passed.
i don't think able implement function way. you're trying pass expression function don't think possible in sql server. may able dynamic sql passing in strings not cleanly you're hoping.
Comments
Post a Comment