[英]sas sql update returns nothing
I have 2 tables - parent and child, with 2 columns in each - id and address, and address looks like this - 我有2个表 - 父和子,每个有2列 - id和地址,地址看起来像这样 -
\\partNumber\\a$\\sometext....\\ - for child \\ partNumber \\ a $ \\ sometext .... \\ - 对于孩子
and \\partNumber\\a$\\ - for parent. 和\\ partNumber \\ a $ \\ - 表示父级。
And I need to make a table out of it with 2 columns - for every child id I need to get its parent folder. 我需要用2列创建一个表 - 对于我需要获取其父文件夹的每个子ID。 I tried to make it like this by using sql 我尝试通过使用sql来实现这一点
update work.Test
set parent_id = ( select pn.DirId
from work.Parent pn
join work.Child cn on cn.dirPath like pn.dirPath & '%');
just tried another option like this one 刚尝试了另一种选择
update work.Test
set parent_id = ( select pn.DirId
from work.Parent pn
join work.Child cn on
cn.dirPath = substr(pn.dirPath, 1, index( '%', pn.dirPath) +1));
but still the same result 但结果仍然相同
And even it gives me 0 error and shows in a log that it did updates on all records, as a final result I get nothing on my table. 甚至它给了我0错误,并在日志中显示它对所有记录进行了更新,因为最终结果我在桌子上什么也得不到。
You can probably just use the EQT
comparison to find the addresses that have similar prefixes. 您可以只使用EQT
比较来查找具有相似前缀的地址。
data child ;
input child_id address $50. ;
cards;
1 \partNumber\a$\sometext....\
2 no_parent
;
data parent ;
input parent_id address $50.;
cards;
501 \partNumber\a$\
;
proc sql ;
create table want as
select a.child_id,b.parent_id,a.address,b.address as parent_address
from child a
left join parent b
on a.address eqt b.address
;
quit;
Results: 结果:
parent_
Obs child_id id address parent_address
1 1 501 \partNumber\a$\sometext....\ \partNumber\a$\
2 2 . no_parent
I'm not sure if I can help not knowing where the table Test comes from. 我不确定我是否可以帮助不知道测试表的来源。
Anyway, cn.dirPath like pn.dirPath & '%'
is very likely not doing what you want. 无论如何, cn.dirPath like pn.dirPath & '%'
很可能不会做你想要的。 Try cn.dirPath like trim(pn.dirPath) || '%'
尝试cn.dirPath like trim(pn.dirPath) || '%'
cn.dirPath like trim(pn.dirPath) || '%'
Edit: I added trim(), pn.dirPath is likely to have trailing blanks. 编辑:我添加了trim(),pn.dirPath可能会有尾随空白。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.