Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error correlating fields
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01533734
Message ID:
01533742
Views:
26
>>>>Hi everybody,
>>>>
>>>>I'm getting the title's error on this SQL
>>>>
>>>>
>>>>SELECT V.*,1 as DupType FROM csrVendors V ;
>>>>INNER JOIN (select MIN(ID) as MinID, UPPER(full_name) as Full_Name FROM csrVendors GROUP BY 2 HAVING COUNT(*) > 1) Dups ;
>>>>ON UPPER(V.full_name) = Dups.full_name AND V.ID > Dups.MinID ;
>>>>UNION ;
>>>>SELECT V.*, 2 as DupType FROM csrVendors V WHERE exists (SELECT full_name FROM i_vendor VV ;
>>>>WHERE UPPER(VV.full_name) = UPPER(V.full_name)) ;
>>>>INTO CURSOR csrVendorDups NOFILTER
>>>>
>>>>Do you see what may be wrong here?
>>>>
>>>>Thanks in advance.
>>>
>>>This is the culprit:
>>>
>>>SELECT V.*, 2 as DupType;
>>>       FROM csrVendors V;
>>>WHERE EXISTS (SELECT full_name;
>>>                     FROM i_vendor VV ;
>>>              WHERE UPPER(VV.full_name) = UPPER(V.full_name)) ;
>>>INTO CURSOR csrVendorDups NOFILTER
>>>
>>>
>>>Change it to:
>>>
>>>SELECT V.*, 2 as DupType;
>>>       FROM csrVendors V;
>>>WHERE EXISTS (SELECT full_name;
>>>                     FROM i_vendor VV ;
>>>              WHERE VV.full_name = V.full_name) ;
>>>INTO CURSOR csrVendorDups NOFILTER
>>>
>>>if you can.
>>
>>Hmm, are you sure? I really want to test based on the upper function as I don't know the case used in advance. I guess I can switch to LEFT JOIN then.
>
>
>
>Test it:
>
>CREATE CURSOR csrVendors (Id I, Full_Name C(20))
>CREATE CURSOR i_vendor (Full_Name C(20))
>
>
>*SELECT V.*,1 as DupType;
>       FROM csrVendors V ;
>INNER JOIN (select MIN(ID) as MinID,;
>                   UPPER(full_name) as Full_Name;
>            FROM csrVendors;
>            GROUP BY 2;
>            HAVING COUNT(*) > 1) Dups ;
>     ON UPPER(V.full_name) = Dups.full_name AND V.ID > Dups.MinID ;
>UNION ;
>
>SELECT V.*, 2 as DupType;
>       FROM csrVendors V;
>WHERE EXISTS (SELECT full_name;
>                     FROM i_vendor VV ;
>              WHERE VV.full_name = V.full_name) ;
>INTO CURSOR csrVendorDups NOFILTER
>BROW NORMAL
>
>SELECT V.*, 2 as DupType;
>       FROM csrVendors V;
>WHERE EXISTS (SELECT full_name;
>                     FROM i_vendor VV ;
>              WHERE UPPER(VV.full_name) = UPPER(V.full_name)) ;
>INTO CURSOR csrVendorDups NOFILTER   && BOOM :-)
>
>
>And becuase you use EXISTS you can use INNER JOIN instead of LEFT.

Yes, I already found out that you're right - I removed the second part and the query worked (got error further). So, can switch to inner join. I forgot that the purpose was to find dups, hence INNER JOIN :)
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform