• Convert has a third parameter that is optional and is called style. It is mostly used with dates. For example check out the next script:

    declare @dt char(10)

    select @dt = '31/01/2010'

    --This will always work

    select convert(smalldatetime, @dt, 103)

    --This might work and might fail

    select cast (@dt as smalldatetime)

    go

    declare @dt char(10)

    select @dt = '01/31/2010'

    --This will always work

    select convert(smalldatetime, @dt, 101)

    --This might work and might fail

    select cast (@dt as smalldatetime)

    Notice that with the convert function, I was able to work with the string as date regardless of the format that I was using because of the third parameter, but when I used cast function only one format could be cast to smalldatetime.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/