November 30, 2010 at 12:11 pm
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 !
November 30, 2010 at 12:22 pm
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
November 30, 2010 at 12:35 pm
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 !
November 30, 2010 at 12:36 pm
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
November 30, 2010 at 12:40 pm
ok, thanks !
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply