首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将if then逻辑实现到sql代码

无法将if then逻辑实现到sql代码
EN

Stack Overflow用户
提问于 2019-12-04 16:33:22
回答 1查看 87关注 0票数 0

想要将SAS代码更改为SQL,但不知道应该遵循哪种方法,但我尝试了case when,它给了我错误。

SAS代码:

代码语言:javascript
复制
length list_of_Fields $400.;
list_of_Fields = "";

if missing(column_a)        eq 1 then do; if calc_of_count <= limit_of_Count then list_of_Fields = catx(" ;", calculation_of_columnName, "Company1"); calc_of_count + 1; end;
if missing(column_b)        eq 1 then do; if calc_of_count <= limit_of_Count then list_of_Fields = catx(" ;", calculation_of_columnName, "Company2"); calc_of_count + 1; end;


if list_of_Fields eg "" then list_of_Fields = &strNone

SQL代码:

代码语言:javascript
复制
case 
    when column_a is null then case when calc_of_count <= limit_of_Count then ist_of_Fields = catx(" ;", calculation_of_columnName, "Company1") 
    when column_b is null then case when calc_of_count <= limit_of_Count then list_of_Fields = catx(" ;", calculation_of_columnName, "Company2") 

不幸的是没能完成,你能帮我找一下路吗?

EN

回答 1

Stack Overflow用户

发布于 2019-12-04 16:57:42

您可以通过以下方式完成此操作:

代码语言:javascript
复制
CASE 
    WHEN (column_a is null AND calc_of_count <= limit_of_Count) THEN ist_of_Fields = CONCAT(" ;", calculation_of_columnName, "Company1") 
    WHEN (column_b is null AND calc_of_count <= limit_of_Count) THEN list_of_Fields = CONCAT(" ;", calculation_of_columnName, "Company2") 
    ELSE list_of_Fields = &strNone
END

您也可以尝试使用以下格式的IF子句:

代码语言:javascript
复制
IF(condn, TRUE_STATEMENT, FALSE_STATEMENT);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59171865

复制
相关文章

相似问题

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