• rocky_498 (8/2/2013)


    Luiz thank you for your help, however that sql is just for one e.g. How I can use your sql on one column?

    Year could be 2013 or 2012 or any year and same as date and month.

    Thank You.

    The code Luis posted will work on one column. You didn't provide a table to work with so he just made a table with a single row with your sample data.

    Try it out on your table. And if at all possible you should consider changing the datatype in your original table to datetime instead of the varchar/int that it is currently.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/