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,098 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

813 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

18 Experts available now in Live!

Get 1:1 Help Now