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,091 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
Comment Utility

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
Comment Utility
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
Comment Utility
September only have 30 days.
0
 
LVL 8

Expert Comment

by:SNilsson
Comment Utility

 "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
Comment Utility
Gee - what was I thinking ....

(Anyway - my application needs better error checking)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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

743 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

14 Experts available now in Live!

Get 1:1 Help Now