I need to convert Datetime fields to a specifically formatted INT type. For example, I want
2000-01-01 00:00:00.000
to convert to 20010101
.
What is the most performant way to make that conversion for comparison in a query?
Something like:
DATEPART(year, orderdate) * 10000 + DATEPART(month, orderdate) * 100 +
DATEPART(day, orderdate)
or
cast(convert(char(8), orderdate, 112) as int)
What's the most performant way to do this?