Showing posts with label encourage. Show all posts
Showing posts with label encourage. Show all posts

Sunday, February 12, 2012

CAST vs CONVERT

What's your opinion? Should I encourage our developers to use CAST or
CONVERT? Personally, I would think CAST should be preferred since it's
the ANSI SQL-92 syntax and CONVERT should only be used where you need to
specify the datetime conversion "style" when converting to a string.
*mike hodgson* |/ database administrator/ | mallesons stephen jaques
*T* +61 (2) 9296 3668 |* F* +61 (2) 9296 3885 |* M* +61 (408) 675 907
*E* mailto:mike.hodgson@.mallesons.nospam.com |* W* http://www.mallesons.comSeems like personal preference to me... Personally, I usually use CONVERT, j
ust because I like the syntax more.
--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Mike Hodgson" <mike.hodgson@.mallesons.nospam.com> wrote in message news:eeG
ZFLHGFHA.1456@.TK2MSFTNGP09.phx.gbl...
What's your opinion? Should I encourage our developers to use CAST or CONVE
RT? Personally, I would think CAST should be preferred since it's the ANSI
SQL-92 syntax and CONVERT should only be used where you need to specify the
datetime conversion "style" when converting to a string.
mike hodgson | database administrator | mallesons stephen jaques
T +61 (2) 9296 3668 | F +61 (2) 9296 3885 | M +61 (408) 675 907
E mailto:mike.hodgson@.mallesons.nospam.com | W http://www.mallesons.com|||I agree with you. I like to use CAST whenever possible. But I don't
think it's ideal, since you still need CONVERT when dealing with dates.
I'd be interested in knowing if anyone has encountered any differences
between the two functions.
David Gugick
Imceda Software
www.imceda.com
"Mike Hodgson" <mike.hodgson@.mallesons.nospam.com> wrote in message
news:eeGZFLHGFHA.1456@.TK2MSFTNGP09.phx.gbl...
What's your opinion? Should I encourage our developers to use CAST or
CONVERT? Personally, I would think CAST should be preferred since it's
the ANSI SQL-92 syntax and CONVERT should only be used where you need to
specify the datetime conversion "style" when converting to a string.|||>> Should I encourage our developers to use CAST or CONVERT?
Personally, I would think CAST should be preferred since it's the ANSI
SQL-92 syntax <<
Of course, and for the reason you gave. Would you require them to
write documentation in a local slang or Standard English?
conversion "style" when converting to a string. <<
I don't much like CONVERT() even for that. Standard SQL uses only the
ISO-8601 format, as do the rest of the ISO standards. Let the local
front end decide how to do the display, so the local user sees it in
whatever format his tribe wants.|||>> Should I encourage our developers to use CAST or CONVERT?
Personally, I would think CAST should be preferred since it's the ANSI
SQL-92 syntax <<
Of course, and for the reason you gave. Would you require them to
write documentation in a local slang or Standard English?
conversion "style" when converting to a string. <<
I don't much like CONVERT() even for that. Standard SQL uses only the
ISO-8601 format, as do the rest of the ISO standards. Let the local
front end decide how to do the display, so the local user sees it in
whatever format his tribe wants.|||"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:eEDgIPHGFHA.228@.TK2MSFTNGP15.phx.gbl...
> I agree with you. I like to use CAST whenever possible. But I don't
> think it's ideal, since you still need CONVERT when dealing with dates.
> I'd be interested in knowing if anyone has encountered any differences
> between the two functions.
A couple of years ago I recall doing some sort of test for a project I
was working on and determining that convert was faster than cast. But I
have no recollection of what or how I tested. I just ran a quick test and
found them to be identical in the case of converting strings to integers...
So I'm not sure that my test then was valid... It would be interesting to do
a comprehensive test of different available casts and find out whether one
or the other really is faster.
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--