Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass-Through Query Syntax Error 1

Status
Not open for further replies.

stevo1961

Technical User
Nov 12, 2014
18
IE
Trying to learn to do a pass-through query with the following but I am getting syntax error trying to get data from a table called dbo.Sales Invoices from our SQL Server.

SELECT dbo.Sales Invoices.SalesInvoiceID, dbo.Sales Invoices.SalesInvoiceDate
FROM dbo.Sales Invoices;

ODBC---call failed.
[Micosoft][ODBC SQL Server Driver][SQL Server]Lne 1: Incorrect syntax near ‘,’,(#170)

Could anyone let me know what I am doing wrong?

Thanks
 
The problem seems to be the space in your table name.
You should use the SQL Server syntax to quote it.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV and Duane,
I figured it had to be the space in the table name. Unfortunately, this an old access table created and upsized to SQL server before my time. I was asked for a solution to speed up a the printing of a Sales Invoice report which uses a query with 6 tables linked via ODBC. It is taking approximately 5 minutes to generate this invoice as it's pulling to many records from these 6 tables from SQL Server through the network to the users desktop for processing. I am not a SQL Server programmer nor have ever used T-SQL Pass-Through Query before so I am a newbie at this. I am still learning about the SQL Server syntax so still need to get my head around this and don't have a clue where to put these single quotes.

I am able to create a pass-through for this with no problem.

SELECT dbo.Companies.Name, dbo.Companies.Address1
FROM dbo.Companies;

But still can't get this to work without the syntax error showing up

SELECT dbo.Sales Invoices.SalesInvoiceNo, dbo.Sales Invoices.SalesInvoiceDate
FROM dbo.Sales Invoices;
 
Did you try this ?
SELECT SalesInvoiceNo, SalesInvoiceDate FROM dbo.'Sales Invoices'
or this ?
SELECT SalesInvoiceNo, SalesInvoiceDate FROM dbo."Sales Invoices"
or this ?
SELECT SalesInvoiceNo, SalesInvoiceDate FROM dbo.[Sales Invoices]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

2nd and 3rd one worked for me.
Although, I am still confused with single quotes and brackets, thought these were only Access properties and not T-SQL properties. Seems I still have a long way too go with learning this.

Thank you very much again for your assistance...
 
Stevo1961,
Congrats on testing the waters by using pass-through queries. You will find them very efficient for reporting and other purposes. The records pulled using a p-t are not editable.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top