Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Shaped Recordsets parent/child relationships

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-13 : 01:47:07
mike writes "I have a shaped recordset that displays all the records from the parent table and selected records from the child record. The problem is how can I display only records from the parent table only if the is a child record ?

cn.Open "Provider=MSDATASHAPE;Data Provider=SQLOLEDB;Server=FFWAPP3;UID=sa;PWD=;Database=Accounting"
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
cmd.CommandText = "SHAPE {SELECT * FROM Expense order by Expense_number} AS Expense " & _
"APPEND ({SELECT * FROM JEP WHERE Ac_location =? and Account_TBCategory =? and Ac_profit_dept =?} AS Accounts " & _
"RELATE Expense_number TO Ac_profit_expense) AS rsJEP"
'

' Set parameters
'
cmd.Parameters.Refresh
cmd.Parameters(0).Value = strLoc
cmd.Parameters(1).Value = strTBC
cmd.Parameters(2).Value = strPosting"

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2002-05-13 : 05:39:50
I think the fastest method would be to restrict the recordset in the SELECT of the parent query. Try something like:

"SELECT *
FROM Expense
WHERE Expense_number in (SELECT Ac_profit_expense FROM JEP)"
Go to Top of Page
   

- Advertisement -