adding specific column data w.rto date, where TOTAL_ELECTRONIC_VALUE which s already added

  • Pls help me with this issue..

    this is my query

    SELECT

    PROCESSING_DATE,

    [ACL_BALANCE_CM] =SUM(TOTAL_ELECTRONIC_VALUE)

    FROM ODS.FUNDS_POOL_BALANCE

    WHERE PROCESSING_DATE between '16-May-2012' and '28-May-2012'

    and PROCESSING_DATE=CONVERT(VARCHAR(10),DATEADD(d,-1,'17-May-2012'),101)

    group by PROCESSING_DATE

    order by 1

    which is generating result as PROCESSING_DATE-

    ACL_BALANCE_CM-653215.42 ( which s added column(TOTAL_ELECTRONIC_VALUE) with respect to date. that means if for date '16-May-2012' there are 2 entries then with this above query, it will add all the columnvalues for tat particular date from the actual table .

    This is fine.,

    Now my requirement s if i give PROCESSING_DATE= '17-May-2012' i need to add [ACL_BALANCE_CM] for processing date and the previous date ...(eg.'17-May-2012' ,'16-May-2012' )

    Actually [ACL_BALANCE_CM] is coming from SUM(TOTAL_ELECTRONIC_VALUE-- which is the actual column name in the table)

    Now again i need to add this [ACL_BALANCE_CM] for the date which i have given and its previous one

    My thought s only we can achieve this with cursors only, bcoz sum(column name) means it will add all the column data, but only for some particular rows only i need to add data .. i am confused...

    Please give me quick respone. (if u also suggests it can be achivable with cursor only, then i need related code, as am fully new to cursors)

    Responded people are highly appreciated, thanks in advance.

  • Definitely do not need a cursor for this.

    declare @ProcessingDate date = '17-May-2012'

    PROCESSING_DATE > dateadd(d, @ProcessingDate, -1)

    and PROCESSING_DATE <= @ProcessingDate

    If that doesn't point you in the right direction, take a look at the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    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/

  • Hi,

    It is not working.. can u pls eloborate that one..

  • anushamsbi (8/17/2012)


    Hi,

    It is not working.. can u pls eloborate that one..

    Rather than saying "it's not working", which is close to useless to us, please provide details of what you tried and the text of any error messages you received.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • anushamsbi (8/17/2012)


    Hi,

    It is not working.. can u pls eloborate that one..

    Can you elaborate on "It is not working"? What does that mean? Did you get an error message? Did it not return the desired results?

    If that doesn't point you in the right direction, take a look at the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    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/

  • What?? Does NOONE have a working crystal ball?? :w00t:

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

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