I have a scalar function that looks up the current date (based on GETDATE()) in a table and returns a single value. The function accept three parameters: {MonthOffset}, {return_field}, and {CompanyId}. The {return field} is a VARCHAR(2) value that specifies which column value is to be returned - i.e. 'E' for ending_date, 'B' for beginning_date, ...
If I call the function as:
SELECT [dbo].[HCS_fn_FiscalPeriodYear](-1, 'B', 'ABCDEF')
I get a proper return of the beginning_date.
If I call the function as :
DECLARE @CompanyID VARCHAR(12)
SET @CompanyID = 'ABCDEF'
SELECT [dbo].[HCS_fn_FiscalPeriodYear](-1, 'B', '@CompanyID')
I get a return value from the function of 0 that is the error trap value in the function.
Why am I NOT able to pass the variable value to the function and get a proper return? Thanks in advance...