我有两个包含多列的表。现在我想使用 like 运算符合并它们。 我的代码就像是
proc sql;
select a.*,b.*
from tera.SFTP as a,home.SFTP_1 as b
where a.zip_c like ('%b.zip_extract%')
;
quit;
我收到分页符消息,但没有返回结果。 a.zip_c的列类型为Char,长度为50,而对于b.zip_extract,其长度为6的Char。
答案 0 :(得分:2)
问题是你匹配字符串b.zip_extract而不是列。
尝试:
select a.*,b.*
from tera.SFTP as a,home.SFTP_1 as b
where a.zip_c like '%' || b.zip_extract || '%'
答案 1 :(得分:2)
合并like
不是一个好主意;它没有使用索引,也没有使用你获得的大量优化。但是,有时候这是必要的。
在SAS中,我做的不同[在大多数其他SQL中......]
proc sql;
select a.*,b.*
from tera.SFTP as a,home.SFTP_1 as b
where find(a.zip_c,b.zip_extract)
;
quit;
这与LIKE完成相同的事情,但更有可能允许SAS使用索引和优化,并且写得更清楚。
要处理可能的列长问题,请使用TRIM:
data have_a;
length zip_c $50;
input @1 zip_c $50.;
datalines;
12345 99999
67890 99999
88001 99999
37013 99999
60037 99999
;;;;
run;
data have_b;
length zip_extract $7;
input zip_extract $;
datalines;
12345
37013
99998
;;;;
run;
proc sql;
title "No Rows!";
select a.*,b.*
from have_a as a,have_b as b
where find(a.zip_c,b.zip_extract)
;
quit;
proc sql;
title "Rows!";
select a.*,b.*
from have_a as a,have_b as b
where find(a.zip_c,trim(b.zip_extract))
;
quit;