vendredi 7 août 2020

SQL IF inside a Function

ALTER FUNCTION [dbo].[FSmapping] (
    @runID as bigInt,
    @TypMap as char(1)
    )

RETURNS TABLE
AS
RETURN


IF (@TypMap ='C')
BEGIN
SELECT b.[A/C],g.accountNumber, b.[Process], g.[endingBalanceLC], g.beginningBalanceLC
FROM table1 g
LEFT JOIN  table2  b ON b.[Acc2]=g.Account_Synt
where RunID = @runID
END

I am trying to implement a table function in SQL. Basically it should have 3 more IFs and the only thing that's going to switch is the table2, from table2-4 based on inputs C I R S. The error is the IF statement, I know that something is missing, I am having a hard time implementing some sort of a switch function with table as a return value. The Select works flawlessly without the IF syntax, it also says errors on the two variables inside the IF

Must declare the scalar variable runID and TypMap

Aucun commentaire:

Enregistrer un commentaire