Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select records if field in 2nd table is in a list of val
Message
 
To
23/07/2007 17:35:37
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01242994
Message ID:
01243003
Views:
28
This message has been marked as the solution to the initial question of the thread.
I think I got it wrong in my first reply:
SELECT Table2.*
FROM Table2
INNER JOIN (SELECT table1.inci_id
                  FROM Table1
            WHERE  table1.inci_id = thisform.pcInci_Id
                or table1.inci_Id = thisform.pcParent_Id
                or table1.parent_id = thisform.pcInci_Id
                or (LEN(table1.parent_id)>0 AND table1.parent_id = thisform.pcParent_Id)) Tbl1
ON Table2.inci_id = Tbl1.inci_id
Is this SQL Server query or VFP one?
If it is SQL Server you should use a parameters instead of thisform properties, even if it is VFP one I prefer to iuse variables instead of properties.



>I did that Naomi but I keep getting the error at EXISTS. Given my day Friday, perhaps it is as simple as a typo, so I will double-check that...
>
>
>
>>>Tables exist SQL2000 or SQL2005:
>>>
>>>I have 2 string values: thisform.pcInci_Id and thisform.pcParent_Id
>>>I want to pull all records from one table whose inci_id value exists in a result from another table
>>>
>>>
>>>Long Way:
>>>
>>>1.  Retrieve table1.inci_id field from all records in table1 where
>>>       table1.inci_id = thisform.pcInci_Id
>>>       or table1.inci_Id = thisform.pcParent_Id
>>>       or table1.parent_id = thisform.pcInci_Id
>>>       or (LEN(table1.parent_id)>0 AND table1.parent_id = thisform.pcParent_Id)
>>>
>>>2.  Get all fields in all records in table2 where
>>>       table2.inci_id is in (the cursor result created in step 1)
>>>
>>>
>>>For some reason I am stumped on the short way! Any ideas?
>>
>>
>>select * from Table1 where exists (select * from ... )
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform