grh
asked on
SQL problem in VB5
My VB prog executes two or so SQL queries in succession. Originally the results of the first SQL statement were written to a WORKTABLE1 (in the 'host' MDB file) and the second SQL statemment used this WORKTABLE1 as part of the source for the second SQL query that attempted to write the results of that query to a second WORKTABLE2 again in the 'host' MDB file.
This worked (I know I could have used recordsets, but I wanted to stick reasonably closely to the SQL-approach)
The problem arises when I try to create/read from WORKTABLES created in a second 'scratch' MDB file...ie
query one...
SELECT Company.company, [job table].[Job No]
INTO WorkTable1 IN C:\Scratch.mdb
FROM Company
INNER JOIN [job table]
ON Company.Company_ID=[Job Table].[Customer ID]
WHERE [Job table].CompDate is not null ;
query two...
SELECT WorkTable1.company,FORMAT( sum([Quoted_Items].[Total Price]),'0.00') AS TotalValue
INTO WorkTable2 IN C:\Scratch.mdb
FROM WorkTable1 IN C:\Scratch.mdb
INNER JOIN [Quoted_Items]
ON [Quoted_Items].Jobid= WorkTable1.[Job No]
GROUP BY WorkTable1.company;
Query two returns a 'Syntax error in FROM clause'
It is the 'second' WORKTABLE2 that causes the problem (the approach works OK when only WORKTABLE1 is involved)
Similarly, the following SQL structure also gives rise to the same 'syntax error in FROM clause' message....
SELECT WorkTable1.Dealing, Staff.Fullname, FORMAT(WorkTable1.TotalVal ue,'£0.00' )
FROM WorkTable1 IN C:\Scratch.mdb
INNER JOIN Staff
ON Staff.Initials = WorkTable1.Dealing;
Any help appreciated,
Garry
This worked (I know I could have used recordsets, but I wanted to stick reasonably closely to the SQL-approach)
The problem arises when I try to create/read from WORKTABLES created in a second 'scratch' MDB file...ie
query one...
SELECT Company.company, [job table].[Job No]
INTO WorkTable1 IN C:\Scratch.mdb
FROM Company
INNER JOIN [job table]
ON Company.Company_ID=[Job Table].[Customer ID]
WHERE [Job table].CompDate is not null ;
query two...
SELECT WorkTable1.company,FORMAT(
INTO WorkTable2 IN C:\Scratch.mdb
FROM WorkTable1 IN C:\Scratch.mdb
INNER JOIN [Quoted_Items]
ON [Quoted_Items].Jobid= WorkTable1.[Job No]
GROUP BY WorkTable1.company;
Query two returns a 'Syntax error in FROM clause'
It is the 'second' WORKTABLE2 that causes the problem (the approach works OK when only WORKTABLE1 is involved)
Similarly, the following SQL structure also gives rise to the same 'syntax error in FROM clause' message....
SELECT WorkTable1.Dealing, Staff.Fullname, FORMAT(WorkTable1.TotalVal
FROM WorkTable1 IN C:\Scratch.mdb
INNER JOIN Staff
ON Staff.Initials = WorkTable1.Dealing;
Any help appreciated,
Garry
The reason why it shouldn't work (so if wgw's proposed answer works, I'd be pleasantly surprised) is because using IN dbname requires you that all the tables (including the ones you're joining) are to be found in the same database.
In other words, IN should be placed after the join and furthermore it expects to find the tables 'quoted_items' and 'staff' in the C:\scratch.mdb
In other words, IN should be placed after the join and furthermore it expects to find the tables 'quoted_items' and 'staff' in the C:\scratch.mdb
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
p_biggelaar: true
so you are implying the (s)he should fetch both table in the temp mdb and join them there
</wqw>
so you are implying the (s)he should fetch both table in the temp mdb and join them there
</wqw>
ASKER
Thanks, the advice helped and saved me spending time looking for another solution.
Garry
Garry
SELECT WorkTable1.company,FORMAT(
INTO WorkTable2 IN 'C:\Scratch.mdb'
FROM WorkTable1 IN 'C:\Scratch.mdb'
INNER JOIN [Quoted_Items]
ON [Quoted_Items].Jobid= WorkTable1.[Job No]
GROUP BY WorkTable1.company;
HTH,
</wqw>