Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

informix query to update a temp table

Posted on 2010-09-07
5
Medium Priority
?
1,863 Views
Last Modified: 2013-12-24
trying to up update a temp table using Aqua Data studio conencting to an informix DB

audit1 temp table
mks_prospectid is blank want to update it
ID        mks_prospectid
1        
2
3

client1 temp table
ID        newclientid
1         101
2          111
3           52523

after the below sql is run we want the audit1 temp table to show the same results as newclientid when the both tables are matched by ID - but we get a syntax error?

-- audit1 – temp table
-- client1 – temp table

update audit1
set mks_prospectid = (select newclientid from client1)
inner join client1 on mks_prospectid = clientid



0
Comment
Question by:JCTDD
  • 3
5 Comments
 
LVL 7

Expert Comment

by:jhp333
ID: 33624038
The correct query is:

update audit1
set mks_prospectid = (select newclientid
                                       from client1
                                    where audit1.mks_prospectid = client1.clientid)
0
 
LVL 7

Expert Comment

by:jhp333
ID: 33624043
OR if you do like to use join:

update audit1
set mks_prospectid = client1.newclientid
from audit1 inner join client1
        on audit1.mks_prospectid = client1.clientid
0
 
LVL 7

Expert Comment

by:jhp333
ID: 33624054
It seems that in both queries,

"audit1.mks_prospectid = client1.clientid"

should be modified to:

"audit1.auditid = client1.clientid"

or

"audit1.ID = client1.ID"

depending on the actual name of the ID column.
0
 

Author Comment

by:JCTDD
ID: 33624175
for this query:
update audit1
set mks_prospectid = (select newclientid
                                       from client1
                                    where audit1.mks_prospectid = client1.clientid)

get err
>[Error] Script lines: 1-3 --------------------------

 [Informix][Informix ODBC Driver][Informix]Cannot modify table or view used in subquery.



another query we use get the same err

update mktngsurvey_bcs
set mks_newclientid = (select newclientid from pro_bcs
                        inner join mktngsurvey_bcs on prospect_id = mks_prospectid
                        and newclientid is not null and newclientid <> '')
where exists  ( select mks_prospectid from mktngsurvey_bcs
inner join pro_bcs on mks_prospectid = prospect_id)


>[Error] Script lines: 1-7 --------------------------

 [Informix][Informix ODBC Driver][Informix]Cannot modify table or view used in subquery.
update mktngsurvey_bcs
0
 
LVL 5

Accepted Solution

by:
flutophilus earned 2000 total points
ID: 33628845
Attached code snippet does what you say you want to achieve.

F.
create temp table audit1 (
id integer,
mks_prospectid integer);

insert into audit1 (id) values(1);
insert into audit1 (id) values(2);
insert into audit1 (id) values(3);

create table client1 (
id integer,
clientid integer);

insert into client1 values(1,101);
insert into client1 values(2, 111);
insert into client1 values(3, 52523);

update audit1
set mks_prospectid =
(select client1.clientid 
from client1
where client1.id = audit1.id)
where 1=1;

select * from audit1;

id  mks_prospectid
1   101
2   111
3   525253

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question