× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Rick:

The SQL would be as follows:

update file1 
set code = (select newcode
                   from file1,
                        file2
                  where vend1 = vend2)
Where exists (Select newcode
                   from file1,
                        file2
                  where vend1 = vend2)

The error you would get with the statement you showed is: [SQL0811] Result of 
SELECT more than one row. 

Here is my attempt to try and explain it:

If you run your select clause:  select newcode From file1, file2 where vend1 = 
vend2 you end up with a result set that contains all the records in file1 and 
matching records in file 2.  What is happening when you say SET CODE = 
(SELECT....) is you are saying SET CODE = (RESULT SET).  You can not set a 
field = to a result set.

The second Where is what tells SQL to process one record at a time and set Code 
= Newcode.  I'm not sure the exists is necessary, but having it does not hurt!

----------------------------------------
snip......
        from: "Richard B Baird" <rbaird@xxxxxxxxxxxxxxxxxxxxx>
        subject: While we're on the subject, a more complicated SQL question.
        all this SQL talk, and I come up with a doozie.
        can you do a UPDATE to one file based on the contents of another file?
        Something like this:

        file1  (has all vendors)
        vend1
        code
        other
        stuff

        file2  (only has selected vendors, not all)
        vend2
        newcode

        now, I'm just guessing, to give you the idea of what I'm trying to do:

        update file1
         set code = (select newcode
                   from file1,
                        file2
                  where vend1 = vend2)

        am I on the right track, or am I just p***ing in the wind?

        thanks,

        rick
------------------------------


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.