-5

How can I use IF ELSE statements inside A multi-statement TVF ? My Cide goes like this

CREATE FUNCTION Production.ms_tvf_ProductCostDifference
(
@ID INT ,

)
     RETURNS @retCostDifference TABLE
     (
      ProductId INT ,
      CostDifference MONEY
    )
    AS
    BEGIN

    With ABC as 
     ( Select ------
     )
    if @ID ='1'
    //some code using ABC defined
    ELSe IF @ID=2
    //Somecode
    Return;
    END

How should be the flow?

user2490024
  • 75
  • 1
  • 2
  • 7

1 Answers1

0

You cant use IF inside a WITH

instead you need something like this

  if @ID ='1'
    With ABC as 
         ( Select ------
         )
        //some code using ABC defined
  ELSE IF @ID=2
      With ABC as 
         ( Select ------
         )
      //Somecode
  Return;
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118