Solved

Problem with SQL 2005 Date Statement

Posted on 2009-07-06
4
276 Views
Last Modified: 2012-05-07
Here is the Statement,
ALTER PROCEDURE [dbo].[p_ST_TimeSheet_SelectByPersonAndDate]
      @p_PersonID int,
      @p_StartDate DateTime,
      @p_FinishDate DateTime
AS
SELECT TimeSheetID, TimesheetGUID, PersonID, PersonGUID, JobID, JobGUID, JobNumber, StartDateTime, FinishDateTime, Activity, Note,
      UpdatedDate, UpdatedBy, CreatedDate, CreatedBy, isDurationPeriod, isChargeable, IsPostedToJobSheet
FROM t_ST_TimeSheet
WHERE PersonID = @p_PersonID AND StartDateTime >= @p_StartDate AND FinishDateTime < @p_FinishDate

When I try to execute
p_ST_TimeSheet_SelectByPersonAndDate 3,'01/01/1700','07/08/2001'
I get the error
Msg 8114, Level 16, State 1, Procedure p_ST_TimeSheet_SelectByPersonAndDate, Line 0
Error converting data type varchar to datetime.
Any date year >1900 is fine.  But could someone tell me how to correct this SQL statement please?
0
Comment
Question by:deeznutz
4 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 24789172
The earliest date you can pass to a datetime is January 1, 1753.
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24789192
I guess '01/01/1700' is out of range for datetime fields - min value is 01/01/1753!
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24789227
If in SQL Server 2005 the minimum date is 1st January 1753, in SQL Server 2008 we have a new data type with minimum date 1st January 0001.
Also, check this article out on how to extend dates to include dataes less than 1753-01-01:
http://weblogs.sqlteam.com/mladenp/archive/2006/12/16/52754.aspx
Hope this helps.
P.
0
 
LVL 1

Author Closing Comment

by:deeznutz
ID: 31600356
Thanks for all responses but seeing as this was the first answer I must award points here as they are basically the same. :)
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 Server maintenance plan 8 53
SQL 2012 AOG and SQL2014 AOG 76 58
SQL Consolidate rows 3 24
add stored proc on publlication 4 15
In this article I will describe the Detach & Attach 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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

680 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