Sql server 在多语句TVF Sql Server中使用多IF-ELSE
如何在多语句TVF中使用IF-ELSE语句?我的工作是这样的Sql server 在多语句TVF Sql Server中使用多IF-ELSE,sql-server,sql-server-2008,user-defined-functions,sql-function,Sql Server,Sql Server 2008,User Defined Functions,Sql Function,如何在多语句TVF中使用IF-ELSE语句?我的工作是这样的 CREATE FUNCTION Production.ms_tvf_ProductCostDifference ( @ID INT , ) RETURNS @retCostDifference TABLE ( ProductId INT , CostDifference MONEY ) AS BEGIN With ABC as ( Select
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
流程应该是怎样的?如果
中的带有
相反,你需要这样的东西
if @ID ='1'
With ABC as
( Select ------
)
//some code using ABC defined
ELSE IF @ID=2
With ABC as
( Select ------
)
//Somecode
Return;
我收到一些sytax错误。。在IF和insert语句更新问题时,不要在问题本身的注释中添加重要信息,只需检查语法即可。谷歌搜索“T-SQLIF”会在第一个结果中返回它