• graham 47698 (10/19/2012)


    Hi

    I have a table which has columns containing sales values for each month for example..

    Id, versionId, jul,aug,sep,oct,nov,dec,jan,feb,mar,apr,may,jun

    The 'versionId' joins to the period table which has the end dates for each month

    versionId, juldate,augdate,sepdate,octdate,novdate,decdate,jandate,febdate,madater,aprdate,maydate,jundate

    What i need to do is return individual rows for each month with the corresponding period date..

    Id

    versionId

    salesvalue

    salesenddate

    I have been looking at Multi-Statement Table-Value Functions but haven't been able to get anywhere near this result..

    Any assistance greatly appreciated..

    As previously stated this does sound like a PIVOT or a cross tab. If you want some help you need to provide enough information so we can help. Please read the article on best practices found at the first link in my signature.

    _______________________________________________________________

    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/