Iver Erling Arva
asked on
Please help with simple PS/SQL-script
Hi!
This works:
This works:
Select n.ID_NO,c.REMINDER_GROUP,c.CUST_NO,n.NAME_TYPE
from TTT.NAME n, TTT.CUSTOMER c
where c.CUST_NO = n.ID_NO
and c.REMINDER_GROUP <> 3
and n.NAME_TYPE = 1
Can anyone explain why this doesn't work:
update TTT.CUSTOMER c
set c.REMINDER_GROUP = 3
where c.CUST_NO = TTT.NAME.ID_NO
and c.REMINDER_GROUP <> 3
and TTT.NAME.NAME_TYPE = 1
And neither does this:
update cust set cust.REMINDER_GROUP = 3
on TTT.CUSTOMER cust inner join TTT.NAME n
where cust.CUST_NO = n.ID_NO
and cust.REMINDER_GROUP <> 3
and n.NAME_TYPE = 1
Thanks for any help!
ASKER
Thanks for your answer, but I cannot see how any of those examples would work, as I want to set the value of REMINDER_GROUP to a fixed value of 3 for all records that match the WHERE statement. I don't want to set it to the result of a sub-query.
For each row in the TTT.CUSTOMER-table found by this query:
IVer
For each row in the TTT.CUSTOMER-table found by this query:
select c.rowid
from TTT.NAME n, TTT.CUSTOMER c
where n.ID_NO = c.CUST_NO
and c.REMINDER_GROUP <> 3
and n.NAME_TYPE = 1
I want to set REMINDER_GROUP to 3IVer
ASKER
Fixed it:
IVer
update CUSTOMER
set REMINDER_GROUP = 3
where CUST_NO in
(
select cu.CUST_NO
from NAME n
inner join
CUSTOMER cu
on cu.CUST_NO = n.ID_NO
where cu.REMINDER_GROUP <> 3
and n.NAME_TYPE = 1
)
did the trick.IVer
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for IverErling's comment #a39650898
for the following reason:
This script did exactly what I was looking for.
Accepted answer: 0 points for IverErling's comment #a39650898
for the following reason:
This script did exactly what I was looking for.
I am really not after the points, but I have the feeling that this kind of closing a question is not "ok"...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thumbs up *rolling eyes*
Well, that went well...
Well, that went well...
TTT.NAME is not referenced within the update = error
You will have to use either sub selects or inner joins or merges to solve this...
some examples:
MERGE:
Open in new window
SUB SELECT:
Open in new window
INNER JOIN:
Open in new window