• aar.mba (4/17/2014)


    I have to convert nvarchar to date data type. and fetch the week number of that particular month from the column

    Pls find the sample data

    CREATE TABLE #mytable

    (

    current_week nvarchar(30)

    )

    insert into (current_week)

    select '2012-02-24 ~~ 2012-03-01' union all

    select '2012-01-20 ~~ 2012-01-26' union all

    select '2012-01-20 ~~ 2012-01-26 ' union all

    select '2012-01-20 ~~ 2012-01-26 ' union all

    select '2012-01-27 ~~ 2012-02-02' union all

    select '2012-02-03 ~~ 2012-02-09' union all

    select '2012-02-17 ~~ 2012-02-23' union all

    select '2012-02-17 ~~ 2012-02-23' union all

    ;

    This table bears the hallmarks of an absolute beginner and will forever be a pig to use. Can you create and use your own table instead of this silly rubbish?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden