Implicit Conversions

  • I have a Integer column in a table which is basically the datekey,e.g 20101101.

    If I want to get only the year and month from this column is it better to use left(datekey,6) OR datekey/100.

    The Left would use implicit conversion.

    Which would be faster ?

    Thanks !

  • Either will work, since you won't be dividing by numbers high enough to cause rounding errors. Both are horrible ideas. Why not store the dates as dates?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thx for the reply.

    I know both will work. The datekey is already stored as an integer in the table.

    What I need now is just the first 6 digits from this column. So if datekey is 20111009, I need the query to return 201110.. nothing more.

    My question was more in regards to which is a better way of doing it in terms of cost and CPU times.

    Any inputs on that ?

    Thanks !

  • It's an integer. Math will be faster.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • ok, thanks !

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply