Solved

Conversion failed when converting datetime from character string.

Posted on 2007-12-03
2
1,791 Views
Last Modified: 2012-08-13
When I exec to search, I am getting an error message:
"Conversion failed when converting datetime from character string."
Which I couldn't understand. I checked everything and make sure that datatype is correct.
Please help me.


Create Proc SearchBoard (

      @RegisterDateFrom      datetime      = Null
,      @RegisterDateTo            datetime      = Null
)
AS
Set NoCount ON

If @RegisterDateFrom is not null
      Select BoardID      From Board
      where RegisterDate >='@RegisterDateFrom' and RegisterDate <'@RegisterDateTo'
      Order by RegisterDate Desc
--------------------------------------
exec searchboard @RegisterDateFrom='12-01-2007', @RegisterDateTo='12-02-2007'
0
Comment
Question by:erin027
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20401306
Create Proc SearchBoard (

      @RegisterDateFrom      datetime      = Null
,      @RegisterDateTo            datetime      = Null
)
AS
Set NoCount ON

If @RegisterDateFrom is not null
      Select BoardID      From Board
      where RegisterDate >=@RegisterDateFrom and RegisterDate <@RegisterDateTo  
      Order by RegisterDate Desc
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 20401312
You dont need to put the quotes around the variables '@RegisterDateFrom' and '@RegisterDateTo'
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question