How do I get my UPDATE statement to function on ctree?

383 views Asked by At

So I am writing a script that both inserts and updates based on a certain condition. I have the insert statement finished but having a hard time trying get my UPDATE statement to work in CTREEACE DATABASE script section. If there is anybody familiar with ctree that could help please take a look and see if there is something wrong with my syntax.

UPDATE act
SET tbl71.address = act.address
FROM act
INNER JOIN tbl71 ON act.address = tbl71.address
WHERE dates = '7/31/2018'

act view 
----------
trackingid(varchar)
delivery_time(varchar)
state(varchar)
address(varchar)                             
city(varcahr)
zipcode(varchar)
dates(varchar)

tbl71 view 
----------
trackingid(varchar)
delivery_time(varchar)
state(varchar)
address(varchar)
city(varcahr)
zipcode(varchar)
dates(varchar)

If an address exists based upon dates within the act view from tbl71 then update all columns in act from tbl71

1

There are 1 answers

5
letronas On

At the beginning check these 8 rules:

  1. The view is defined based on one and only one table
  2. The view must include the PRIMARY KEY of the table based upon which the view has been created
  3. The view should not have any field made out of aggregate functions
  4. The view must not have any DISTINCT clause in its definition
  5. The view must not have any GROUP BY or HAVING clause in its definition
  6. The view must not have any SUBQUERIES in its definitions
  7. If the view you want to update is based upon another view, the later should be updatable. Any of the selected output fields (of the view) must not use constants, strings or value expressions

Next one problem is that idk why are you trying to update column from another view (tbl71) using from (act),but it's up to you.

If this example doesn't work it's ok:

UPDATE act
SET act.address = tbl71 .address
FROM act
INNER JOIN tbl71 ON act.address = tbl71.address
WHERE dates = '7/31/2018'

Try to see the result of this simple query to see that union or join works:

    SELECT *
    FROM act
    INNER JOIN tbl71 ON act.address = tbl71.address

After this try to add *"Where":

SELECT *
FROM act
INNER JOIN tbl71 ON act.address = tbl71.address
WHERE dates = '7/31/2018'

And finally try to get in update. The easiest way can be to recreate a views (make a 1 view instead of 2, that will get the final data that you need.)