Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Cast Error Blank Varchar to Datetime

$
0
0

I have a rather large sql statement that was generating the message "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value".  I stripped the statement down to a more basic form while still getting the message.  Heres what Im working with:

SELECT        AUG.RESIDDED
FROM            MLS_Amenities_FLAT_WILM_RESI AS AUG INNER JOIN
                View_Properties AS PR ON AUG.Listing_RID = PR.Listing_RID
WHERE        (PR.Listing_RID IN (210912, 213273))
ORDER BY CAST(AUG.RESIDDED AS DATETIME)

RESIDDED is a varchar column.  Seems to me it should be a date column, but for now I have to leave it as is.  The Listig_RID is a primary key, and records 210912 and 213273 are very similar, both with blank('') RESIDDED fields.  If I remove the cast statement, it works fine.  If i run each record individually, it runs fine.  If i add a third (or more) record, even if that third record has a blank RESIDDED, it works fine.  If i strip out the inner join and just select and sort from the AUG table, it works fine.  Any other two records with blank RESIDDED fields work fine.  But something about those two records together is causing a problem.  I realize this is probably a data specific error and I may not be giving enough info, but any thoughts?  Perhaps theres some other relationship between those tables that I should be examining?



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>