I'm trying to create an user defined function with take 2 parameters the federal filing status char 1 where have data like S and M which are single and married and the second parameter is state char 2 where have data created already in a table EmployeeTransfers have MS,FL,NY etc..
I have create a functoin that returns one of the code which is of data type char 1 with this logic example: IF State = NY and Federal Filing Single(S) then Code is A or Federal Filing Married(M) then Code is B
etc...
so there my code my returns are NULL i dnt knw how to set the return more specific
create function dbo.GetStateFilingStatus
(
@federalfilingstatus char(1),
@state char(2)
) returns char(1)
as
begin
declare @code char(1) = null
select @federalfilingstatus = EmpFederalFilingStatus from EmployeeTransfers
where @state = EmpTransferState
if (@state = 'MS' AND @federalfilingstatus = 'S')
set @code = 'A'
return @code
if (@state = 'MS' AND @federalfilingstatus = 'M')
set @code = 'M'
return @code
if (@state = 'NJ' AND @federalfilingstatus = 'S')
set @code = 'B'
return @code
if (@state = 'NJ' AND @federalfilingstatus = 'M')
set @code = 'A'
return @code
if (@state = 'AZ' AND @federalfilingstatus = 'S')
set @code = 'A'
return @code
if (@state = 'AZ' AND @federalfilingstatus = 'M')
set @code = 'B'
return @code
if (@state = 'CT' AND @federalfilingstatus = 'S')
set @code = 'F'
return @code
if (@state = 'CT' AND @federalfilingstatus = 'M')
set @code = 'M'
return @code
if (@state = 'DC' AND @federalfilingstatus = 'S')
set @code = 'S'
return @code
if (@state = 'DC' AND @federalfilingstatus = 'M')
set @code = 'Y'
return @code
end
Go
I tried to execute it with
select dbo.GetStateFilingStatus(EmpTransferState ,EmpFederalFilingStatus) as StateFilingStatus from EmployeeTransfers
my returns are nulls.