Cannot get this statement to update the table and am almost certain my problem is in concatenation syntax.
Please take a look and tell me if you see what I am going wrong here..
Thank you !!
UPDATE TAB1 s
SET s.user_NUM =
(select e.USER#
from TAB2 e
where ('e.LAST_NAME'||','||' E.FIRST_NAME')= s.DEALER);
I think those are supposed to be columns in TAB2? If so, you need to drop the quote marks:
Otherwise you’re looking to match records in TAB1
where DEALER = 'e.LAST_NAME, E.FIRST_NAME'(i.e. a literal), which I don’t think is what you meant at all.So, more than one row in TAB2 matches a row in TAB1. This now becomes an investigation into your data.
If there is only one occurrence of
e.USER#fore.LAST_NAME||', '||E.FIRST_NAMEyou’re fine: you can just add DISTINCT into the sub-query. Check that with:If that query returns any rows you’re going to need to decide how to handle multiple hits.
Likewise, you need to decide what action to take if there is no row in TAB2 which matches a row in TAB1. At the moment that’s going to set
s.user_NUMto NULL. Maybe that’s what you want.These are decisions about business rules: only you know what you want to do.