Kerala Microsoft Users Group

Sum of variant multiple columns in sql server

Latest post 03-09-2012 1:28 PM by NinethSense. 2 replies.
  • 03-01-2012 5:03 AM

    Sum of variant multiple columns in sql server

     

    Hi All,

           I have a temporary table creating dynamically with N columns. This column count will vary according to some specific conditions (eg: sometimes with count 10, sometimes with count 15...)..Say, the columns names as Jan_2011,Feb_2011. sometimes the column willl reach upto Sep_2011, sometimes to Dec_2011.Now my problem is , I want the sum of all these varying columns . Is there any sql query or we have to pass all these column names as parameters to get the result ?

    thanks in advance

     

    regards,

    Razik

             

    • Post Points: 45
  • 03-02-2012 11:37 AM In reply to

    Re: Sum of variant multiple columns in sql server

    Little bit complex I think - Check - http://www.dbforums.com/microsoft-sql-server/1647680-sum-all-columns-new-columns.html

    If you dig to system level access (sys.columns/information_schema), then you can make a logic.

    May be think about CLR SP?

    Praveen V Nair, PMP
    Tech Blog | PM Blog

    • Post Points: 5
  • 03-09-2012 1:28 PM In reply to

    Re: Sum of variant multiple columns in sql server

    I wonder whether you found some good solution for this. If so, please share.

    Praveen V Nair, PMP
    Tech Blog | PM Blog

    • Post Points: 5
Page 1 of 1 (3 items) | RSS