Hi Guys, got a SQL problem.
I have three tables they are linked as such
Client links to Deals via client.iid = Deals.Clientid
Deals links to DealDetail_Hdr via Deals.Dealid = DealDetail_Hdr.Dealid
I am trying to write a SQL statement that will read the Clients tbl and for each client read will return the max cost for item=card(s). The item Card(s) and its cost are kept on the DealDetail_Hdr tbl.
Here is what I came up with:
strSQL = "SELECT Max(DealDetail_Hdr.COST) AS MaxOfCOST, DealDetail_Hdr.Item " _
& "FROM Clients " _
& "INNER JOIN DealDetail_Hdr On Deals.DealID = DealDetail_Hdr.DEALID " _
& "Inner JOIN Deals ON Clients.ID = Deals.ClientId " _
& " WHERE clientid = " & sID & " And Item = " & "Card(s)"
Set rst = db1.OpenRecordset(strSQL)
If rst.RecordCount > 0 Then
sCards = rst!MaxCards
write_rec = -1
End If
I am getting an error msg that there is a problem with the Join portion of the statement.
Any ideas?
Thanx
Trudye
I have three tables they are linked as such
Client links to Deals via client.iid = Deals.Clientid
Deals links to DealDetail_Hdr via Deals.Dealid = DealDetail_Hdr.Dealid
I am trying to write a SQL statement that will read the Clients tbl and for each client read will return the max cost for item=card(s). The item Card(s) and its cost are kept on the DealDetail_Hdr tbl.
Here is what I came up with:
strSQL = "SELECT Max(DealDetail_Hdr.COST) AS MaxOfCOST, DealDetail_Hdr.Item " _
& "FROM Clients " _
& "INNER JOIN DealDetail_Hdr On Deals.DealID = DealDetail_Hdr.DEALID " _
& "Inner JOIN Deals ON Clients.ID = Deals.ClientId " _
& " WHERE clientid = " & sID & " And Item = " & "Card(s)"
Set rst = db1.OpenRecordset(strSQL)
If rst.RecordCount > 0 Then
sCards = rst!MaxCards
write_rec = -1
End If
I am getting an error msg that there is a problem with the Join portion of the statement.
Any ideas?
Thanx
Trudye