Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with SQL 2005 Date Statement

Posted on 2009-07-06
4
Medium Priority
?
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

722 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