?
Solved

Conversion failed when converting datetime from character string.

Posted on 2007-12-03
2
Medium Priority
?
1,797 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 1000 total points
ID: 20401312
You dont need to put the quotes around the variables '@RegisterDateFrom' and '@RegisterDateTo'
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

777 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