If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > ASP, SQL and Quotation Syntax...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-03, 22:48
fergy fergy is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
ASP, SQL and Quotation Syntax...

I am trying to construct an SQL statement using VB Script. I want to retrieve all of the records of a certain year...

SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart("y", Table.DatePlayed) = 2003 "

I get an error page stating...

Expected end of statement at the quotation marks:
... DatePart("yyyy" ...

I have tried this with double quotes, single quotes, no quotes, double single quotes, etc., but no luck!

Anyone?

Thanks,

fergy
Reply With Quote
  #2 (permalink)  
Old 02-04-03, 23:56
nigelrivett nigelrivett is offline
Registered User
 
Join Date: Oct 2001
Location: England
Posts: 426
SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart('yy', Table.DatePlayed) = 2003"
Reply With Quote
  #3 (permalink)  
Old 02-05-03, 00:43
fergy fergy is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
When modifying it to your suggestion I get the error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
Reply With Quote
  #4 (permalink)  
Old 02-05-03, 01:23
nigelrivett nigelrivett is offline
Registered User
 
Join Date: Oct 2001
Location: England
Posts: 426
Ah access.
try
SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart(""y"", Table.DatePlayed) = 2003"

Can't remember the datepart systax for access but something like this.
Reply With Quote
  #5 (permalink)  
Old 02-05-03, 10:30
fergy fergy is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Quote:
Originally posted by nigelrivett
Ah access.
try
SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart(""y"", Table.DatePlayed) = 2003"

Can't remember the datepart systax for access but something like this.

With the double quotes around it I get:

Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
Reply With Quote
  #6 (permalink)  
Old 02-05-03, 16:00
Memnoch1207 Memnoch1207 is offline
Registered User
 
Join Date: Jan 2003
Location: Midwest
Posts: 138
I'll just throw this in here...

SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart("yyyy", Table.DatePlayed) = 2003"
Reply With Quote
  #7 (permalink)  
Old 02-05-03, 16:07
fergy fergy is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Quote:
Originally posted by Memnoch1207
I'll just throw this in here...

SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart("yyyy", Table.DatePlayed) = 2003"

When trying your suggestion, Iget the following:

Microsoft VBScript compilation error '800a0401'

Expected end of statement


It seems the quotations are throwing the syntax out of whack. How can you use datepart in an SQL statement if you can't use quote characters?
Reply With Quote
  #8 (permalink)  
Old 02-05-03, 16:16
Memnoch1207 Memnoch1207 is offline
Registered User
 
Join Date: Jan 2003
Location: Midwest
Posts: 138
SELECT DatePlayed FROM table WHERE DatePart("y", DatePlayed) = 2003

OR

SELECT DatePlayed FROM table WHERE DatePart(year, DatePlayed) = 2003
Reply With Quote
  #9 (permalink)  
Old 02-05-03, 16:17
nigelrivett nigelrivett is offline
Registered User
 
Join Date: Oct 2001
Location: England
Posts: 426
That would cause problems with the embedded quote - would have to be


SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart(""yyyy"", Table.DatePlayed) = 2003"

tried this in access and it doesn't lik Table - don't know if you have that as the name

SQL = "SELECT Table.Dateplayed FROM [Table] WHERE DatePart(""yyyy"", Table.DatePlayed) = 2003"


Shouldn't give the 2 expeted parameters error though.
Can you post the code you are using.
And do you succeed with other similar queries?
Reply With Quote
  #10 (permalink)  
Old 02-05-03, 17:39
fergy fergy is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Quote:
Originally posted by nigelrivett
That would cause problems with the embedded quote - would have to be


SQL = "SELECT Table.Dateplayed FROM Table WHERE DatePart(""yyyy"", Table.DatePlayed) = 2003"

tried this in access and it doesn't lik Table - don't know if you have that as the name

SQL = "SELECT Table.Dateplayed FROM [Table] WHERE DatePart(""yyyy"", Table.DatePlayed) = 2003"


Shouldn't give the 2 expeted parameters error though.
Can you post the code you are using.
And do you succeed with other similar queries?
The double quotes you suggested above doesn't do it. I've constructed numerour SQL statements in the past with no difficulty. However, I have never tried building one that required the use of quotation marks, other than for variable names and strings in WHERE clauses.

Here is the code I am working with in my asp script:
---------------------------------------------------------
IF StatTimeFrame = "Career" THEN
set rs = db.execute("SELECT Rounds.*, Rounds.MemberID FROM Rounds WHERE Rounds.Status = 'LOCKED' )
ELSE
set rs = db.execute("SELECT Rounds.*, Rounds.MemberID, Rounds.Dateplayed FROM Rounds WHERE Rounds.Status = 'LOCKED' AND Rounds.MemberID <> '"&MemberName&"' AND StatTimeFrame = DatePart(""yyyy"", Rounds.DatePlayed) ")
END IF
---------------------------------------------------------

The first SQL statement above works fine. I have confirmed that the second SQL statement works fine without the DatePart code. The DatePart code does in fact cause the difficulty.

By the way, thanks for your help!
Reply With Quote
  #11 (permalink)  
Old 02-05-03, 19:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
fergy, in the meantime, while you are digging out the appropriate docs about how to escape a doublequote in ASP or whatever you're using, you can bypass the problem with this workaround --

change

StatTimeFrame = DatePart("yyyy", Rounds.DatePlayed)

to

StatTimeFrame = year(Rounds.DatePlayed)


rudy
http://rudy.ca/
Reply With Quote
  #12 (permalink)  
Old 02-05-03, 23:14
fergy fergy is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Quote:
[SIZE=1]Originally posted by r937

change

StatTimeFrame = DatePart("yyyy", Rounds.DatePlayed)

to

StatTimeFrame = year(Rounds.DatePlayed)
Even when I attempt this workaround, I get the following error:

Too few parameters. Expected 1.
Reply With Quote
  #13 (permalink)  
Old 02-05-03, 23:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
"Too few parameters. Expected 1." is a simple syntax error

what query did you get this on?

not the ASP code that builds the query, but the query string after any variables have been suffed into it
Reply With Quote
  #14 (permalink)  
Old 02-06-03, 10:09
fergy fergy is offline
Registered User
 
Join Date: Feb 2003
Posts: 7
Quote:
Originally posted by r937
"Too few parameters. Expected 1." is a simple syntax error

what query did you get this on?

not the ASP code that builds the query, but the query string after any variables have been suffed into it
Well, I've found the problem I had with implementing your suggested work - around. In fact it wasn't the work-around that was the issue. It was actually the following:

year(Rounds2.DatePlayed) = StatTimeFrame

I failed to put puntuation around my variable name. I corrected it to be:

'"&StatTimeFrame&"'

I still can't get this to work using the DATEPART function, as the quotation marks cause syntax errors. However, using the workaround above solves the problem.

I sincerely thank everyone for their help on this issue.

fergy
Reply With Quote
  #15 (permalink)  
Old 04-03-03, 17:07
jmadrid jmadrid is offline
Registered User
 
Join Date: Apr 2003
Location: Granville, Ohio, US
Posts: 1
Arrow

I know this issue has already been solved but another solution to the problem would have been the following:

Where you use
StatTimeFrame = DatePart("yyyy", Rounds.DatePlayed)

Replace the quotes arount yyyy with 4 single quotes
StartTimeFrame = DatePart(''''yyyy'''', Rounds.DatePlayed)

When the SQL is being executed, it will interpret the 4 single quotes with as 1 double quote.

Hope this is of help to someone in the future.

-Jon

www.madridcom.com

Last edited by jmadrid; 04-03-03 at 17:11.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On