Solved

Conversion failed when converting datetime from character string.

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now