Solved

informix query to update a temp table

Posted on 2010-09-07
5
1,765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to trim my database size 9 53
Need a mirrored QA test site 2 95
sql views 3 57
Access Data Retrieval 1 15
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

752 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