Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 多案例串联_Sql_Oracle_Concatenation_Case - Fatal编程技术网

Sql 多案例串联

Sql 多案例串联,sql,oracle,concatenation,case,Sql,Oracle,Concatenation,Case,我需要使用多个CASE语句来连接表中的两列 这是scneario,我们如何才能做到这一点 在我的选择中,我们将表A中的col1+col3连接起来 从表A中, 当col2值为NULL且 如果COL3值为0000 然后从表B的COL1中选择值 否则,如果COL3值不等于0000 从表B的COL2中选取值 表A: col1 col2 col3 aa null 0000 bb null 1234 表b: col1 col2 col3 LMNO PQRST 我试过这样的东西但不起作用 sel

我需要使用多个CASE语句来连接表中的两列

这是scneario,我们如何才能做到这一点

在我的选择中,我们将表A中的col1+col3连接起来

从表A中, 当col2值为NULL且 如果COL3值为0000 然后从表B的COL1中选择值 否则,如果COL3值不等于0000 从表B的COL2中选取值

表A:

col1 col2 col3
aa   null 0000
bb   null 1234
表b:

col1 col2  col3
LMNO PQRST
我试过这样的东西但不起作用

select
 (a.col1 || '+' || a.col3) 
 CASE WHEN (a.col2 IS NULL) THEN
    CASE WHEN (a.col3 = '0000') THEN
     (Select col1 from b)
     ELSE (a.col3 <> '0000')
     (Select col2 from b)
 ELSE
  a.col2 
 as TEST

假设联接条件基于a.column\u将\u具有相同的\u值=b.column\u将\u具有相同的\u值


这是你期待的吗

proc sql;
select 
case
    when a.col2 is null and a.col3='0000' then a.col1||b.col1
    when a.col3<>'0000' then a.col1||b.col2
end as value

from tablea a, tableb b;
quit;

各种情况下的样本数据和预期输出将非常有用。查询需要在endrealation处的A中有另一列,该列在两个表中具有相同的值Post第三个表与关系请澄清
proc sql;
select 
case
    when a.col2 is null and a.col3='0000' then a.col1||b.col1
    when a.col3<>'0000' then a.col1||b.col2
end as value

from tablea a, tableb b;
quit;