Solved

Problem with SQL 2005 Date Statement

Posted on 2009-07-06
4
240 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

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.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 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

12 Experts available now in Live!

Get 1:1 Help Now