Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I am getting error while executing the below script.Select DT_YR,DT_MNTH,DT_DT from table whereCAST(CAST(DT_YR AS VARCHAR) + RIGHT('0' + CAST(DT_MNTH AS VARCHAR), 2) + RIGHT('0' + CAST(DT_DT AS VARCHAR), 2) AS DATETIME) Between '1/1/2008' And '2/2/2008' Columns are int type..Error: Syntax error converting datetime from character stringThanks for your help in advance.
PeterNeo
Constraint Violating Yak Guru
357 Posts
Posted - 2008-12-12 : 00:27:37
try this
Select DT_YR,DT_MNTH,DT_DT from table whereCAST(RIGHT('0' + CAST(DT_MNTH AS VARCHAR(10)), 2) +'/' + RIGHT('0' + CAST(DT_DT AS VARCHAR(10)), 2) + '/' + CAST(DT_YR AS VARCHAR(10)) AS DATETIME) Between '1/1/2008' And '2/2/2008'
"There is only one difference between a dream and an aim.A dream requires soundless sleep to see,whereas an aim requires sleepless efforts to achieve..!!"
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-12-12 : 01:51:24
declare @day int, @month int, @year intselect @day=12,@month=3,@year=2008select dateadd(day,@day-1,dateadd(month,@month-1,dateadd(year,@year-1900,0)))Use the above logicMadhivananFailing to plan is Planning to fail