Solved

Conversion failed when converting datetime from character string.

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Date from a string 4 70
Stored procedure 4 35
Strange msg in the SSMS pane 13 58
MS SQL Server - Looking to filter rows based on column value 3 48
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article I will describe the Backup & Restore 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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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