![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
select wo1.* from cwko wo1; where; wo1.isgwo and wo1.wostatus#"V" and exists; (; select wo2.wonbr from cwko wo2; where; wo2.wonbr#wo1.wonbr and wo2.isgwo and wo2.wostatus#"V" and; (; (wo2.trndtlow between wo1.trndtlow and wo1.trndthi) or; (wo2.trndthi between wo1.trndtlow and wo1.trndthi) or; (wo2.trndtlow<wo1.trndtlow and wo2.trndthi>wo1.trndthi); ); ); order by wo1.clcode,wo1.wonbr |
#3
| |||
| |||
|
|
select wo1.* from cwko wo1; where; There should be a space in the first line between wo1 and ; |
#4
| |||
| |||
|
|
select wo1.* from cwko wo1; where; wo1.isgwo and wo1.wostatus#"V" and exists; (; select wo2.wonbr from cwko wo2; where; wo2.wonbr#wo1.wonbr and wo2.isgwo and wo2.wostatus#"V" and; (; (wo2.trndtlow between wo1.trndtlow and wo1.trndthi) or; (wo2.trndthi between wo1.trndtlow and wo1.trndthi) or; (wo2.trndtlow<wo1.trndtlow and wo2.trndthi>wo1.trndthi); ); ); order by wo1.clcode,wo1.wonbr It's the "exists" part. You need to supply a field name to check against, most likely: |
|
... and wol.wonbr exists ( select wonbr .... ) |
#5
| |||
| |||
|
|
Why does the following query not work? I get an error of "SQL: Error correlating fields.". select wo1.* from cwko wo1; where; wo1.isgwo and wo1.wostatus#"V" and exists; (; select wo2.wonbr from cwko wo2; where; wo2.wonbr#wo1.wonbr and wo2.isgwo and wo2.wostatus#"V" and; (; (wo2.trndtlow between wo1.trndtlow and wo1.trndthi) or; (wo2.trndthi between wo1.trndtlow and wo1.trndthi) or; (wo2.trndtlow<wo1.trndtlow and wo2.trndthi>wo1.trndthi); ); ); order by wo1.clcode,wo1.wonbr I am looking for the work orders that are GWOs, are not void, and where there is another such work order such that their trndtlow to trndthi date ranges overlap. I have tried several variations to no avail. |
#6
| |||
| |||
|
|
Nope. That is not what EXISTS is for. It is not the same as IN. From the VFP 6 docs: |
#7
| |||
| |||
|
|
Why does the following query not work? I get an error of "SQL: Error correlating fields.". select wo1.* from cwko wo1; where; wo1.isgwo and wo1.wostatus#"V" and exists; (; select wo2.wonbr from cwko wo2; where; wo2.wonbr#wo1.wonbr and wo2.isgwo and wo2.wostatus#"V" and; (; (wo2.trndtlow between wo1.trndtlow and wo1.trndthi) or; (wo2.trndthi between wo1.trndtlow and wo1.trndthi) or; (wo2.trndtlow<wo1.trndtlow and wo2.trndthi>wo1.trndthi); ); ); order by wo1.clcode,wo1.wonbr I am looking for the work orders that are GWOs, are not void, and where there is another such work order such that their trndtlow to trndthi date ranges overlap. I have tried several variations to no avail. Sincerely, Gene Wirchenko |
#8
| |||
| |||
|
|
select wo1.* from cwko wo1; where; wo1.isgwo and wo1.wostatus#"V" and exists; (; select wo2.wonbr from cwko wo2; where; wo2.wonbr#wo1.wonbr and wo2.isgwo and wo2.wostatus#"V" and; (; (wo2.trndtlow between wo1.trndtlow and wo1.trndthi) or; (wo2.trndthi between wo1.trndtlow and wo1.trndthi) or; (wo2.trndtlow<wo1.trndtlow and wo2.trndthi>wo1.trndthi); ); ); order by wo1.clcode,wo1.wonbr It's the "exists" part. You need to supply a field name to check against, most likely: ... and wol.wonbr exists ( select wonbr .... ) |
#9
| |||
| |||
|
|
On Thu, 04 Aug 2005 16:51:45 -0700, Gene Wirchenko genew (AT) ucantrade (DOT) com.NOTHERE> wrote: Why does the following query not work? I get an error of "SQL: Error correlating fields.". select wo1.* from cwko wo1; where; wo1.isgwo and wo1.wostatus#"V" and exists; (; select wo2.wonbr from cwko wo2; where; wo2.wonbr#wo1.wonbr and wo2.isgwo and wo2.wostatus#"V" and; (; (wo2.trndtlow between wo1.trndtlow and wo1.trndthi) or; (wo2.trndthi between wo1.trndtlow and wo1.trndthi) or; (wo2.trndtlow<wo1.trndtlow and wo2.trndthi>wo1.trndthi); ); ); order by wo1.clcode,wo1.wonbr I am looking for the work orders that are GWOs, are not void, and where there is another such work order such that their trndtlow to trndthi date ranges overlap. I have tried several variations to no avail. To follow up, I switched to an inner join. select; wo1.clcode,; wo1.wonbr,wo1.wccode,wo1.trndtlow,wo1.trndthi,; wo2.wonbr,wo2.wccode,wo2.trndtlow,wo2.trndthi; from cwko wo1; inner join cwko wo2 on wo1.clcode=wo2.clcode and wo1.wonbr<wo2.wonbr; where; wo1.isgwo and wo1.wostatus#"V" and; wo2.isgwo and wo2.wostatus#"V" and; (; (wo2.trndtlow between wo1.trndtlow and wo1.trndthi) or; (wo2.trndthi between wo1.trndtlow and wo1.trndthi) or; (wo2.trndtlow<wo1.trndtlow and wo2.trndthi>wo1.trndthi); ); order by wo1.clcode,wo1.wonbr I had forgotten to specify the the client codes be equal. Without that, it takes quite a while. The idea of the exists was to get rid of the non-matches quickly. Fortunately, the optimiser handled the above well (quickly). I am still puzzled as to why the exists would not work. I did get exists to work with a simple correlated query of identity. Thanks to those who replied. Sincerely, Gene Wirchenko |
#10
| |||
| |||
|
|
The EXISTS predicate does not take a column name. The correlated subquery following EXISTS does not need a column name either. One usually writes SELECT id FOM Table1 WHERE EXISTS (SELECT * FROM Table2 ; WHERE Table1.id=Table2.id ) |
![]() |
| Thread Tools | |
| Display Modes | |
| |