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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 convert data type implicitly

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2007-02-27 : 17:59:48
I have a code like below...
@startdate is datetime data type
and service_date_thru is varchar..
Even though, these two data has a different data type, the query is still returing the right result...
Can you compare varchar to datetime? Is it becaue SQL server is doing a data conversion implicitly?
I am just curious????


declare @startdate datetime
declare @enddate datetime
set @startdate = '1/1/2007'

update revenue_stage
set inperiod = case when @startdate <= service_date_thru then 1
when @startdate > service_date_thru then 0
else NULL end


sshelper
Posting Yak Master

216 Posts

Posted - 2007-02-27 : 19:05:29
Yes, SQL Server is doing a data conversion implicitly, converting the data type with the lower precedence to the data type of the higher precedence. In your case, a DATETIME data type has a higher precedence than a VARCHAR so your VARCHAR date value is implicitly converted to DATETIME.

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page
   

- Advertisement -