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?
答案 0 :(得分: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;