I've a SQL query which looks like :
select LAST_UPDATED from Employees WHERE (CAST(LAST_UPDATED AS smalldatetime)) > (CAST('@updateTime' AS smalldatetime))
command.Parameters.AddWithValue("updateTime", updatedTime);
I went through several of the related questions asked here and also this page but none could solve my issue.
I also tried the ISO-8601 format for dates (YYYYMMDD) which also doesn't seem to work here.
The data type of LAST_UPDATED column in SQL server is DATE.
The problem is like this works well in development machine and in SQL management studio but throws the following error in Test server:
The conversion of a nvarchar data type to a smalldatetime data type resulted in an out-of-range value
SQL management studio query:
select LAST_UPDATED from Employees WHERE (CAST(LAST_UPDATED AS smalldatetime)) > (CAST('2014-08-10 ' AS smalldatetime))
It would be very helpful if someone can put some light on this.
'@updateTime'
to a smalldatetime - not the value of the@updateTime
variable. – Damien_The_UnbelieverAddWithValue
I recommend useParameters.Add
and defining the datatype of your input parameter in your C# code. – LarnuupdatedTime
value in C#? Might be some date dependent OS settings thats formatting the date that makes SQL Server fail when converting. – EzLoupdatedTime
was being assigned! – m_beta