2013-10-17 53 views
0

我想如在下面的SQL代码来获得功能:Case语句计算领域

select ....... , A.authorizedAction 
, '1 - Add' = Case when (Cast((authorizedAction/1) As Int) % 2) = 1 then 'Y' end 
, '2 - Update/Display' = case when (Cast((authorizedAction/2) As Int) % 2) = 1 then 'Y' end 
, '4 - Update/Display all' = case when (Cast((authorizedAction/4) As Int) % 2) = 1 then 'Y' end 
, '8 - Correction' = case when (Cast((authorizedAction/8) As Int) % 2) = 1 then 'Y' end 
, A.authorizationActionKey .... from .... 

我要代表所有4例(添加,更新/显示,更新/显示所有与更正)作为tableau中工作表的列值。

我发现'case'语句在tableau中是一个有效的函数,但我不确定是否可以得到这种类型的功能。基本上我只给予'授权行动',我需要为上述4种情况创建一个计算字段。我可以以某种方式将这些案例陈述分成一个计算的字段公式吗?

任何帮助表示赞赏。如果你能为我提供一个可以工作的计算场地公式,就不会有这样的效果!

回答

1

在上面的SQL语句中,您有一个输入字段被分成4个输出字段,每个字段可以是'Y'或空白。您可以在Tableau中创建一组类似的4个计算字段,每个字段都有一个公式,沿着

(field name)  (formula) 
Add:    if ([authorizedAction] % 2) = 1 then 'Y' else '' end 
Update/Display:  if (([authorizedAction]/2) % 2) = 1 then 'Y' else '' end 
Update/Display all: if (([authorizedAction]/4) % 2) = 1 then 'Y' else '' end 
Correction:   if (([authorizedAction]/8) % 2) = 1 then 'Y' else '' end