Convert Date

  • I have this query here:

    SELECT

    top 10 left((convert(varchar(10), D_Date, 120)), 13) D_DateValue,

    (replace(convert(varchar(10), D_Date, 120), '-', '')) D_DateID

    FROM

    D_DATE

    What does "left" represent?, "120" represent?, and the second line "Replace"

    Kind Regards

    Hasani

  • Break it down to its component parts

    ie

    Start with

    select convert(varchar(255), D_Date, 120)

    then

    Select convert(varchar(10), D_Date, 120)

    then

    Select left((convert(varchar(10), D_Date, 120)), 13)

    Which is slightly bizzare , taking the left 13 characters of a varchar(10).

    Use Bol (Books on line)as your primary resource the functions are all well documented



    Clear Sky SQL
    My Blog[/url]

  • Hi,

    Left is an inbuilt function that returns left part a string starting from 0 and upto the length specified (13 in your case).

    Replace is another inbuilt string function that will replace a subset of string with another say ',' with ';'.

    and convert function for datetime is well documented which returns datetime in various formats as specified by the code (120 in your case

    which return 'yyyy-mm-dd hh:MM:ss' format) .

    You can also refer Books Online for details.

    Hope that helps

  • Hi

    Thank you very much, can you send me one useful link where I can able to download some T-SQL ebook?

    Kind Regards

    Pitso

  • You could try this...

    http://www.mssqlserver.com/tsql/



    Clear Sky SQL
    My Blog[/url]

  • Any suggestion on specific ebook to use

  • Hi,

    This looks helpful. Thanks alot.

    cool:

Viewing 7 posts - 1 through 6 (of 6 total)

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