首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在case when语句-Snowflake中,无法基于不同的列串接值

在case when语句-Snowflake中,无法基于不同的列串接值
EN

Stack Overflow用户
提问于 2021-11-16 08:52:59
回答 2查看 55关注 0票数 1

希望你做得好!..I我正在尝试连接case的值,当snowflake ..Please中基于不同列的语句找到下面的代码块时

代码语言:javascript
运行
复制
select *,

case when checkouttime is null then ',Patient is not checked out' else '' END
+ case when primarypatientinsuranceid is null then ',No insurance information' else '' END
+ case when closedby is null then ',Encounter not signed off' else '' END
+ case when billingtabcheckeddate is null then ',Billing tab is not checked' else '' 
+ case when alreadyrouted is null then ',Missing slip already routed' else 'Valid Missing slip'

END as resultant

from final

我得到的错误是“意外为”

我正在尝试构建结果列输出,如下所示

代码语言:javascript
运行
复制
Patient is not checked out/Billing tab is not checked
Missing slip already routed
Encounter not signed off/No insurance information /Billing tab is not checked
Valid Missing slip

谢谢,阿伦

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-16 21:53:34

一种更简洁的替代方案,可以根据需要添加逗号,使用array_to_string(array_construct_compact())

代码语言:javascript
运行
复制
with data as (
    select null checkouttime
        , 2 primarypatientinsuranceid
        , null closedby
        , 4 billingtabcheckeddate
        , 5 alreadyrouted
)

select array_to_string(array_construct_compact(
    iff(checkouttime is null, 'Patient is not checked out', null) 
    , iff(primarypatientinsuranceid is null, 'No insurance information', null)
    , iff(closedby is null, 'Encounter not signed off', null)
    , iff(billingtabcheckeddate is null, 'Billing tab is not checked', null)
    , iff(alreadyrouted is null, 'Missing slip already routed', 'Valid Missing slip')
    ), ',  ')
as resultant
from data
票数 1
EN

Stack Overflow用户

发布于 2021-11-16 11:33:34

在Snowflake中,你使用"||“来连接字符串,而不是"+":

代码语言:javascript
运行
复制
select 
case when true then ',Patient is not checked out' else '' END
|| case when false then ',No insurance information' else '' END
|| case when true then ',Encounter not signed off' else '' END
|| case when true then ',Billing tab is not checked' else '' END
|| case when false then ',Missing slip already routed' else 'Valid Missing slip' END 
as resultant;

https://docs.snowflake.com/en/sql-reference/functions/concat.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69986172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档