Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

adding specific column data w.rto date, where TOTAL_ELECTRONIC_VALUE which s already added Expand / Collapse
Author
Message
Posted Thursday, August 16, 2012 7:23 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 20, 2012 10:36 PM
Points: 2, Visits: 15
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.

Post #1345943
Posted Thursday, August 16, 2012 7:29 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:32 PM
Points: 13,067, Visits: 11,903
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1345953
Posted Friday, August 17, 2012 5:24 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 20, 2012 10:36 PM
Points: 2, Visits: 15

Hi,
It is not working.. can u pls eloborate that one..
Post #1346478
Posted Friday, August 17, 2012 7:17 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: 2 days ago @ 11:49 PM
Points: 4,973, Visits: 11,660
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.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1346531
Posted Friday, August 17, 2012 7:18 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:32 PM
Points: 13,067, Visits: 11,903
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1346532
Posted Friday, August 17, 2012 8:20 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:59 PM
Points: 23,000, Visits: 31,482
What?? Does NOONE have a working crystal ball??


Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1346570
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse