Solved

Weird Error Msg 296: conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value

Posted on 2004-10-14
5
5,100 Views
Last Modified: 2008-01-09
SELECT S.StudentID, S.FirstName+' '+S.LastName AS SName, S.EnrollDate , PRs.RecieptID, PRs.TutionFee AS AmountPaid, PRs.PaymentDate, PRs.PaymentMode, PRs.CheckNo, PRs.Comments , PRs.CreditCardName FROM PaymentReciepts AS PRs INNER JOIN Students AS S ON (PRs.LocationID = S.LocationID) AND (PRs.StudentID = S.StudentID) WHERE (((PRs.PaymentDate) Between '09/01/2004' And '09/31/2004' )) ORDER BY PaymentDate Desc

Gives error: Server: Msg 296, Level 16, State 3, Line 1
The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.

HOWEVER - this is not giving an error:
SELECT S.StudentID, S.FirstName+' '+S.LastName AS SName, S.EnrollDate , PRs.RecieptID, PRs.TutionFee AS AmountPaid, PRs.PaymentDate, PRs.PaymentMode, PRs.CheckNo, PRs.Comments , PRs.CreditCardName FROM PaymentReciepts AS PRs INNER JOIN Students AS S ON (PRs.LocationID = S.LocationID) AND (PRs.StudentID = S.StudentID) WHERE (((PRs.PaymentDate) Between '10/01/2004' And '09/10/2004' )) ORDER BY PaymentDate Desc
0
Comment
Question by:MargusLehiste
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:SNilsson
ID: 12310880

Check the PRs.PaymentDate column is the data type smalldatetime ?

If not, check the dates between '09/01/2004' And '09/31/2004' some charactor that dont belong might have slipped in the wrong place.

0
 
LVL 8

Expert Comment

by:MartinCMS
ID: 12310885
try....

WHERE Convert(Varchar(10), PRs.PaymentDate,101) Between '09/01/2004' And '09/30/2004'
ORDER BY PaymentDate Desc
0
 
LVL 8

Accepted Solution

by:
MartinCMS earned 500 total points
ID: 12310890
September only have 30 days.
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 12310953

 "September only have 30 days."

Right on :)

I did not notice, we use the YYYY-MM-DD formate in my country, nice spotted.
0
 
LVL 1

Author Comment

by:MargusLehiste
ID: 12313159
Gee - what was I thinking ....

(Anyway - my application needs better error checking)
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

Suggested Solutions

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

808 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