Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Probably a Syntax Issue in a Between Statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-25 : 09:39:12
Lindsey writes "Help!

I'm trying to show only records between two dates that are entered by a user in the previous HTML form. Here's the code from my results page:


startdate=Request("startdate")
enddate=Request("enddate")

SQL="SELECT pagehits.url, Format([Date_visited], 'mm/dd/yyyy') AS Formatted FROM pagehits WHERE Format([Date_visited], 'mm/dd/yyyy') between startdate and enddate ORDER BY Format([Date_visited], 'mm/dd/yyyy')"

SET RSResponse=db.Execute(SQL)



I keep getting this error for my SQL statement:

Too few parameters. Expected 2.

This is probably a syntax problem, but I'm not sure what the correct syntax is. Please help me! Thanks!"

jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-07-25 : 09:48:50
You are mixing your languages

SQL="SELECT pagehits.url,Date_visited
FROM pagehits WHERE Date_visited between '" & startdate & "' and '" & enddate & "' ORDER BY Date_visited"

If you want the dates return in a prticular format use CONVERT or use client side code (this is where formatting code belongs). Convert your input dates to ISO format before passing them to SQL to avoid any date localisation issues


HTH
Jasper Smith
Go to Top of Page

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-07-25 : 11:16:35
Since you posted in on a SQL Server website, jasper_smith is probably safe in assuming you are querying a SQL Server database. Since you did not mention the database, let me point out that if you are using an Access database and the starttime and endtime are date/time fields in the database, then you would replace the single quotes with #.


SQL="SELECT pagehits.url,Date_visited
FROM pagehits WHERE Date_visited between #" & startdate & "# and #" & enddate & "# ORDER BY Date_visited"

Jeremy



Go to Top of Page
   

- Advertisement -