error sintyax in sql...please!

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

error sintyax in sql...please!

Post by sal21 »

Code here...

Code: Select all

DATA_ACCENSIONE = DateAdd("D", -14, Date)

Set CMD = New ADODB.Command

SQL = "SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= #" & Format(DATA_ACCENSIONE, "mm/dd/yyyy") & _
"# AND TIPO_DATO='" & TEST_COUNT & "'"

With CMD
        .CommandTimeout = 0
        .CommandText = SQL
        .ActiveConnection = OCONN
        .CommandType = adCmdText
        Set OCONN_RS = .Execute
        Set CMD = Nothing
    End With

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: error sintyax in sql...please!

Post by HansV »

You don't specify any field(s) after SELECT.

You changed the code while I posted a reply!
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: error sintyax in sql...please!

Post by HansV »

Please insert the following line below the instruction SQL = ...:

Debug.Print SQL

When you run the code, the SQL string will be written to the Immediate window. Please copy this string and paste it into a reply.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: error sintyax in sql...please!

Post by sal21 »

HansV wrote:Please insert the following line below the instruction SQL = ...:

Debug.Print SQL

When you run the code, the SQL string will be written to the Immediate window. Please copy this string and paste it into a reply.
Immediate window return:

SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= #05/05/2010# AND TIPO_DATO='00'

note:
tipo_dato is formatted TEXT in table field

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: error sintyax in sql...please!

Post by HansV »

The SQL looks OK. But since it looks like you're working with a SQL Server table, try this:

Code: Select all

SQL = "SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= '" & Format(DATA_ACCENSIONE, "mm/dd/yyyy") & _
"' AND TIPO_DATO='" & TEST_COUNT & "'"
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: error sintyax in sql...please!

Post by sal21 »

HansV wrote:The SQL looks OK. But since it looks like you're working with a SQL Server table, try this:

Code: Select all

SQL = "SELECT * from DBO_CC_DAILY WHERE [DATA_ACC] >= '" & Format(DATA_ACCENSIONE, "mm/dd/yyyy") & _
"' AND TIPO_DATO='" & TEST_COUNT & "'"
Tks. work now!

User avatar
Charlotte
Her Majesty
Posts: 499
Joined: 19 Jan 2010, 07:13

Re: error sintyax in sql...please!

Post by Charlotte »

Just to clarify this, Access SQL and the SQL used by SQL Server use different characters to delimit dates, so the same SQL that works in Access may not work in SQL Server and vice versa.
Charlotte

User avatar
Carol W.
3StarLounger
Posts: 390
Joined: 26 Jan 2010, 16:02
Location: Las Vegas, NV

Re: error sintyax in sql...please!

Post by Carol W. »

Charlotte,

Thanks for clarifying this.

I was just about to post a question on this. I know that Access uses the # as a date delimiter. I now see that SQL Server uses a ' as a date delimiter.
Carol W.