If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Update query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-25-04, 16:17
kicker22 kicker22 is offline
Registered User
 
Join Date: Apr 2004
Location: Michigan
Posts: 44
Update query

can someone tell me what is wrong with this update query

UPDATE tblprocessInfo
SET ProgDate = (
SELECT TermInformation.ProgDate
FROM tblProcessInfo, TermInformation
WHERE TermInformation.Term = tblProcessInfo.Term AND TermInformation.SID = tblProcessInfo.SID);


Basically, both tables processInfo and termInformation are similar, except terminformation has extra field "ProgDate".
So what I did, i created that field in tblProcessInfo to import from termInformation.ProgDate.
Now of course the processInfo.progdate is empty and termInformation.Progdate has the stuff...
So I created the query as you can see, but doesnt work..

any solutions or ideas?!

thanks
Reply With Quote
  #2 (permalink)  
Old 06-25-04, 21:19
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
Update tableA ta
set column =
(select column from tableB where key = ta.key)
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #3 (permalink)  
Old 06-26-04, 12:12
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
While your query as written makes logical sense, it will cause consternation for most database engines (MS-SQL included). The problem is that you've used the same table alias twice in a single context, but most optimizers won't realize that, so they'll generate a Cartesian join! You can probably simplify the query down to:
Code:
UPDATE tblprocessInfo 
   SET ProgDate = (
      SELECT TermInformation.ProgDate
      FROM TermInformation
         WHERE TermInformation.Term = tblProcessInfo.Term
            AND TermInformation.SID = tblProcessInfo.SID);
This only uses the tblprocesInfo alias once, and it should prevent the confusion.

-PatP
Reply With Quote
  #4 (permalink)  
Old 06-26-04, 22:21
kicker22 kicker22 is offline
Registered User
 
Join Date: Apr 2004
Location: Michigan
Posts: 44
hmm

thanks..
that makes sense...

I will try it later on
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On