Two Similar SQL select queries. Why does one not work? (1 Viewer)

AJR

Registered User.
Local time
Today, 23:44
Joined
Dec 22, 2012
Messages
59
Hi.

I need to check if a recordset is empty. I did this once before, with much help from this forum, using the following SQL:

Code:
sqlstr = "SELECT [fxXRate] FROM tblFXRates " & _
             "WHERE fxDate= #" & dtSetDate & "#  AND fxCurrency ='" & strCur & "'"

Adapting this to my new, even simpler, query I wrote this SQL

Code:
"SELECT [optTicker]" & _
"FROM tblOptions" & _
"Where  optTicker = '" & strTicker & "'"

and got a "Syntax Error In FROM Statement" error

After putting square brackets around tblOptions in the From statement it worked. As in:

Code:
"SELECT [optTicker]" & _
"FROM [tblOptions]" & _
"Where  optTicker = '" & strTicker & "'"

Can anybody explain why in the first SQL I did not need the [] and in the second I did? I'm hoping to avoid problems in the future.

Thanks

A/R
 

boerbende

Ben
Local time
Today, 17:44
Joined
Feb 10, 2013
Messages
339
in your second query,
"SELECT [optTicker]" & _
"FROM tblOptions" & _
"Where optTicker = '" & strTicker & "'"

When you write this out it is

"SELECT [optTicker]FROM tblOptionsWhere optTicker = '" & strTicker & "'"

So you miss the space between your tablename and where

When you do this, just always end with space AND begin next sentence with space again. Or use brackets yes
 

AJR

Registered User.
Local time
Today, 23:44
Joined
Dec 22, 2012
Messages
59
BoerBende

Thanks -Sometimes the obvious stuff is the hardest to see.

A/R
 

Users who are viewing this thread

Top Bottom