我有一个示例视图定义为;
CREATE view [ab].[udv_SUMMARY] as
select
txt.[Timestamp],
txt.[Site],
txt.[Name],
txt.[Variance]
from [ab].Text_Table txt
我有3个用户定义的函数([udf_BJ_CT],[udf_BJ_MD],[udf_BJ_NY]
我需要根据所有这3个函数的输出更改 Variance 值。
答案 0 :(得分:0)
您可以在此处使用CASE WHEN
。
CREATE view [ab].[udv_SUMMARY] as
select
txt.[Timestamp],
txt.[Site],
txt.[Name],
txt.[Variance],
(CASE WHEN txt.[Site] = {CONDITION 1} THEN dbo.[udf_BJ_CT](txt.[Timestamp],txt.[Site])
WHEN txt.[Site] = {CONDITION 2} THEN dbo.[udf_BJ_MD](txt.[Timestamp],txt.[Site])
WHEN txt.[Site] = {CONDITION 3} THEN dbo.[udf_BJ_NY](txt.[Timestamp],txt.[Site])
ELSE dbo.[Def_Fxn](...)
END)
from [ab].Text_Table txt
您必须使用{CONDITION 1},{CONDITION 2} and {CONDITION 3}