Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 The conversion of char data type to smalldatetime

Author  Topic 

stahorse
Yak Posting Veteran

86 Posts

Posted - 2012-09-06 : 01:29:02
Hi

I have this code below below and when I try to run run it I get this error:
"The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value"

please help.

DECLARE @StartDate VARCHAR(50), @EndDate VARCHAR(50), @UserId VARCHAR(50)

SET @StartDate = '01-07-2001'
SET @EndDate = '29-12-2013'
SET @UserId = 'jamesm'

SELECT [POLICY_ID]
, ISNULL(VALUE,0) [VALUE]
, ISNULL(UNITS,0) [UNITS]
, TX , CASH_FLOW_SET , PRODUCT_CODE , REC_DATE, [DATE]

FROM [Selestia_BI_Staging_Source]..PR_CF_HST CF (NOLOCK)

WHERE cf.[REC_DATE] >= @StartDate AND cf.[REC_DATE] <= @EndDate

AND cf.Fund_Code = 'FV'

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-09-06 : 01:48:12
One option is to change the format to YYYYMMDD . Therefore:
DECLARE @StartDate varchar(50), @EndDate varchar(50), @UserId VARCHAR(50)
SET @StartDate = '20110701'
SET @EndDate = '20131229'
SET @UserId = 'jamesm'

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

stahorse
Yak Posting Veteran

86 Posts

Posted - 2012-09-06 : 01:54:23
Thank you that helped.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-09-07 : 01:47:05
OK. That's the standard format I use , unless time is required as well. ideally, the iso 8601 format - would be used

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-08 : 17:26:46
quote:
Originally posted by stahorse

Thank you that helped.


see

http://visakhm.blogspot.com/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-09-13 : 04:17:50
You need to learn how to use unambiguous date formats
http://beyondrelational.com/modules/2/blogs/70/posts/10898/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -