Solved

Conversion failed when converting datetime from character string.

Posted on 2007-12-03
2
1,772 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
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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