Running Total and In Current Year Columns Source
Hi all,
What is the source for Running Total and In Current Year Columns from Absence Detail Screen.
From Which tables can I get the information on those columns.
Thanks in Advance
Hello,
I am still struck with Running Total Column
When i fetch running total using this query it works for some of the employees
SELECT SUM(ABSENCE_hours) from PER_ABSENCE_ATTENDANCES where person_id = <your person id> and absence_attendance_type_id = <your absence type id>
As there are three different cases here as Days,Hours and No Balance
I am missing the logic again here when it comes for no balance and days
Thanks
Similar Messages
-
Running total and calc between two column (subtraction)
Hi Experts!,
I have a simple requirement but getting me frustrated :( I need to calculate stock on a series of transaction
this is my order table:
OrderNo | Item | Delivery | OrderQty
A-101 | G001 | 20110721 | 200
A-104 | G001 | 20110722 | 300
A-102 | GA02 | 20110721 | 210
and my stock table :
Item | stockQty
G001 | 300
GA02 | 0
What i want to accomplish is something like this:
OrderNo | Item | Delivery | OrderQty | StockOut
A-101 | G001 |20110721 | 200 | 200
A-104 | G001 |20110722 | 300 | 100
A-102 | GA02 |20110721 | 210 | 0
i believe there is must be a way to accomplish this, without using to create extra dummy table to store
qty of Stock out (stock-orderqty),
waiting for respons,
Thanks!Try this
with order1
as
select 'A-101' orderno, 'G001' item, 20110721 delivery, 200 orderqty from dual union all
select 'A-104', 'G001', 20110722, 300 from dual union all
select 'A-105', 'G001', 20110723, 250 from dual union all
select 'A-102', 'GA02', 20110721, 210 from dual union all
select 'A-103', 'GA02', 20110721, 300 from dual
), stock
as
select 'G001' item, 600 stockqty from dual union all
select 'GA02', 500 from dual
select orderno, item, delivery, orderqty, case when qty <= stockqty then orderqty else stockqty - qty1 end stockout
from (
select orderno, item, delivery, orderqty, qty, nvl(lag(qty) over(partition by item order by orderno), 0) qty1, stockqty
from (
select orderno, o.item, delivery, orderqty, sum(orderqty) over(partition by o.item order by orderno) qty, stockqty
from order1 o
join stock s
on o.item = s.item
)Note: Tables defined in the WITH caluse are sample table to show you how the SQL works. You can just use the SELECT statement with your original table. -
How to get and display current year
hi,
how to get and display current year
and need it to convert numeric format if it is orginally
in character format.Hi,
chk this FM.
CALL FUNCTION 'GET_CURRENT_YEAR'
EXPORTING
BUKRS = '1000' " Company Code
DATE = SY-DATUM " Date to find fiscal year for
IMPORTING
CURRM = w_currm " Current Fiscal Month
CURRY = w_curry " Current Fiscal Year
PREVM = w_prevm " Previous Fiscal Month
PREVY = w_prevy. " Previous Fiscal Year
rgds
anver
if hlped pls mark points -
How to Summarized Running Total and Formula ????
Post Author: ryan_r
CA Forum: Crystal Reports
Hi my name is Ryan, I want to ask something. I have build a report
that contains Running totals and Formula. What I want to do is I want
to use subtotal and Summary field for the running total and Formula,
but I can find the field when I click the dropdownlist in the Subtotal
dialog box or summary field for the running total and the formula. Is
there any way that I can use subtotal or summary field for Running
Totals and formula, I do need some help guys, Thanks. FYI: I use Visual Studio.NET 2003; ASP.NET(C#).regardsPost Author: ryan_r
CA Forum: Crystal Reports
Hi kcheeb, thanks for your advice but it doesn't work sorry. By the way maybe I can explain you more of twisted situation.I have updated my report,
so im not using runningtotals any more, I'm using summary field and
formula which are;-the summary field is "Sum of SuspenseVoucher.Realisation" located in Group Footer #3: SuspenseMstr.ProgramID-The formula is "@Balance_Formula" which contain:{SuspenseMstr.Budget}
- Sum ({SuspenseVoucher.PenggunaanBudget}, {SuspenseMstr.ProgramID})
also located in the same location as summary field above.FYI: I have three group records which are:-Group #1 : SuspenseMstr.APDate (Appearing in months e.g January 2007)-Group
#2 : programCategoryMstr.programCategoryID (doesn't have any objects I
just put some dashed line, the group is only for proper sorting)-Group #3: SuspenseMstr.ProgramIDwhat I want to do is:-in the Group Footer #3, I already put "Sum of SuspenseVoucher.Realisation" and "@Balance_formula"-in
the Group Footer #2, I want to put Summary of Budget but there's a
problem in here too, in the budget field there are some data are
conditionally suppressed. I already tried to put some summary field but
the summary operation wasn't like what I wanted. What I wanted was the
sum only evaluate the data that appeared in the report not the
suppressed, but in the summary the suppressed data keep evaluated. And
in this location I also want to put Summary of "Sum of
SuspenseVoucher.Realisation" and the Sum of the @Balance_formula.-
in the Group Footer #1, I want to add some Summary of "Sum of Budget"
(which I already explained that this operation has a problem) and I
also want to put the Sum of "Summary of Sum of
SuspenseVoucher.Realisation" and the Sum of "Sum of @Balance_formula"-And in the Report Footer I want to add some Grand Total from all of the evaluation above.So
there are my problems, quite much I would say. I hope this explanation
helping all of you guys to solve my problem, thanks for spending your
valuable time for me. This matter is really important for me 'cause I
want to learn something new from all of you experts as I'm still a
"toddler" in this situation and also because I work in this field, so a
BIG thank you for all of you guys out there. Best Regards. -
Running total and Next function in Crosstab
<strong><font size="3"><font face="Times New Roman">Clarifications on getting Next Running sum and count on a Crosstab</font></font></strong><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Here is the example, which I am working on:</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Highlights of the Report:</font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt 'Times New Roman'"> </span></span><font size="3">Report is grouped on {Scenario Name}</font></font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt 'Times New Roman'"> </span></span><font size="3">Left side dates on any of the tables is {Version Date}</font></font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt 'Times New Roman'"> </span></span><font size="3">Dates on the top header on any of the tables is {Fsc Week End Dt}</font></font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt 'Times New Roman'"> </span></span><font size="3">Other formulae used in this report are:</font></font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">1) = ({Query1.Demand Qty})/100000</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Numerical values displayed in the "Original values" table.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">2) =</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">if {Query1.Scenario Name} = 'DLYPRD:ASCP-PRD:PRD' </font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">THEN mid ({Query1.Scenario Name},13,3)</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">ELSE mid ({Query1.Scenario Name},13,6)</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Second column with value PRD in any of the tables.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">3) {next qty} = if not onlastrecord then next({@ShortDemandQty}) else 0;</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">(used in the "next values vertically" table)</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">4) - running total to calculate horizontally</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - For each record</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Version Date}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">5) - running total to calculate vertically.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - For each record</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Fsc Week End Dt}</font></p><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">In this report design, when I go and change the Sort order in the Record Sort Expert, some of the values go for a toss. I got two cases where the vertical values are correct in one case and horizontal values are correct in another case.</font></p><font face="Times New Roman" size="3"> </font><strong><font size="3"><font face="Times New Roman">First Case:</font></font></strong> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Cumulative vertical values are correct.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"> </p><font face="Times New Roman" size="3"> </font><strong><font size="3"><font face="Times New Roman">Second Case:</font></font></strong> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Cumulative horizontal values are correct.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"> </p><font face="Times New Roman" size="3"> </font><strong><span style="color: blue"><font size="3"><font face="Times New Roman">Is there any way to consistisize both the horizontal and vertical running totals. I even tried forcing the evaluate & reset like below and clearing the record sort order, but it did not work:</font></font></span></strong><strong><span style="color: blue"><font face="Times New Roman" size="3"> </font></span></strong> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">1) - running total to calculate horizontally</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - On change of field: {Fsc Week End Dt}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Version Date}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">2) - running total to calculate vertically.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - On change of field: {Version Date}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Fsc Week End Dt}</font></p><font face="Times New Roman" size="3"> </font><strong><span style="color: blue"><font size="3"><font face="Times New Roman">And one more observation on the running total, how it works in the crosstab is, the total runs likes a spiral rather than resetting at the column or row level. Is there any way to restrict this?</font></font></span></strong><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">3) {next qty} = if not onlastrecord then next({@ShortDemandQty}) else 0;</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">(used in the "next values vertically" table)</font></p><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">For example, onlastrecord does not seem to work on the "next values vertically" crosstab, rather brings the record from the next column.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">For 3/7/2007 - 01/APR/07, the value is 157.84 which is incorrect and should be 0.</font></p><strong><span style="color: blue"><font size="3"><font face="Times New Roman">I need to get a next on the running total. Next (fld) doesnot work for running totals. Please guide me, how to get the next values for the running total fields.</font></font></span></strong>
Post Author: redtop6683
CA Forum: Formula
Whoops I guess I should have mentioned that I've already tried using Sum and Round(Running Total, 2) and haven't had any luck.
I also should have mentioned that Groupings 1 and 2 are sums, and that Running Total is a running total that changes on every change of the grouping. There are 4 groupings.
Grouping 1 (Employee Name)
Grouping 1.1 (Shift)
Grouping 1.2.1 (Payroll Department Code)
Grouping 1.2.1.1 (Description)
Below these 4 groupings is where the running total is. The issue is that in the footer of grouping 1 is a field that sums the elapsed hours for the particular employee by each payroll department code, these are then summed using the running total. The issue is as stated in the earler post that I can round these individual sums on the groupings, but I get the number on my running total to round differently as you can see by the earlier post's example.
Thanks for the help.
~Jason -
Running Totals and Formulas with Cross Tabs
Hi,
I'm using Crystal Reports 2008 and am having two issues using Cross Tabs.
The first is that I want to have two crosstabs. They both will have a common Y axis (Oppourtunity.Sales Rep), and on the Y Axis I want one to show all (Opportunity.Create Date) where (Opportunity.Staus = Won) and the other where (Opportunity.Staus = In Process), but I can't figure out how to contruct the formula to return this result.
The other issue, is that in addition to summarizing based on Sum (Opportunity.Expected Revenue), I would also like to create a running total to show the cumulative (Expected Revenue) Week over Week.
Any direction would be fantastic.
Thank you,
MichaelPlease go through the SAP Notes listed here which would help you how to create mannual running totals in crosstab
[https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_ossnotes&query=runningtotalin+crosstab&adv=true¬e_number=&component=&sdn_updated_on_comparator=GE&sdn_updated_on=&sortby=cm_rnd_rankvalue]
Regards,
Raghavendra -
Creating a fiscal date table that includes Day of Year and Week of Year column
Hi,
Our fiscal year runs between 1st October through to 30th September and I'm trying to create a date table that I can use to represent this in Powerpivot (I'm using Excel 2013). I had no probably creating columns for Fiscal month or fiscal year, however I am
having issue breaking it down more than that, specifically I cannot work out how to calculate:
- day of the year
- week of the year (with week one starting on the first day of the year rather than the first Monday)
I worked out how to do the day of the year until I had to try and account for leap years which broke the formula I had! Can anyone please recommend solutions, I cannot see anything online about this. Obviously I know that it is simple to do this for a normal
calendar year but this approach doesn't work with a custom fiscal year.
Whilst it is useful for several reasons, my main reason for wanting week is so that I can plot my Pivotcharts more smoothly (although I may have missed an easier way to do that).
Thanks,
JamesFor my example I started with 1 column in Power Pivot called [Date]
I created the following Columns
[DayofMonth] =Day([Date])
[MonthNumber] =Month([Date])
[Fiscal Year] =IF([MonthNumber]< 10, Year([Date]), (Year([Date])+1))
[Fiscal Day] =[Date] - DATE(([Fiscal Year] -1), 10,1) +1
[Fiscal Week] =RoundUp([Fiscal Day] / 7, 0)
Change [Date] to whatever your date column is and those DAX formulas will get you what you need -
Current Year and Previou year Data comparision - Urgent
Hi Experts,
In our report we need to compare the sales value for current year and prevous year.
The Fiscal year is the input selection field.
Output report displayed as below
Product|Current year sales|Previous year sales|
404 |120.00 |20.00
400 |122.00 |22.00
Total |242.00 |42.00
Could any body help how do i use the fiscal year/period or fiscal year for the current sales and previous sales values.
Thanks in advance.
MahanteshYou have to restricit current year column with the variable Fiscal year and previous year colum with same variable with offset -1.
For year period use a range with from valie '001.1990' and to value a variable for current and the same variable with offset -12 for previous.
Hope it helps.
Regards -
Calculating Running Totals in Columns
I am trying to calculate running totals in Dynamic columns
I have data that is monthly and want to create a running total in the columns.
Data Format in:
Material|Type|Month|Qty
Query Report Ex:
Material|Type| Nov-05| Dec-05| Jan-06| Feb-06
PART1| DEMAND| -42 EA| -46 EA| -33 EA| -3 EA
PART1| SUPPLY| 58 EA| 0 EA| 0 EA| 49 EA
Result| | 16 EA| -46 EA| -33 EA| 46 EA
I would like running total taken from totals from previous columns + current column total are dynamic:
Result| | 16 EA| -30 EA| -63 EA| -17 EA
.continues for more parts
PART2
Thanks,
Mike Walker
FMC Technologies Inc.I am still having problems with this.
I have not figured out a way to control the Results row that is genereated to be a running total. Without having the data also becoming a running total.
I am wanting an new running total line. And not the standard Results row unless I can make it a running total and it leaves the data alone.
Material|Type| Nov-05| Dec-05| Jan-06| Feb-06|....<Dynamic>
PART1| DEMAND| -42 EA| -46 EA| -33 EA| -3 EA|....<Dynamic>
PART1| SUPPLY| 58 EA| 0 EA| 0 EA| 49 EA|....<Dynamic>
Standard Results Row:
Result| | 16 EA| -46 EA| -33 EA| 46 EA
I want this. Running total of the standard results.
Result| | 16 EA| -30 EA| -63 EA| -17 EA
I will look more on this next week.
Thanks. -
How to show current year and last year sales in a WEBI Report
Hi Guys
How can show current YEar Sales in one column and Last YEar Sales in the other column based on a user prompt for the Current YEar Column.
For Example is user enter 2010 for Year how can i show a Column for Sales-2010 and Sales 2009.
ThanksIf you can modify your Universe add an object named New Object Last Year whose SQL is:( yourTableName.Year + 1)
Then in WebI create two distinct queries in your query Pane. In the first one you could do this:
Query 1:
objects: Year, Sales ... etc.
filters: Year Equal to '1. Prompt Year'
Query 2:
objects: Year, Sales ... etc.
filters: New Object Last Year Equal to '1.Prompt Year'
Then in your report you can drag each object on their respective columns.
If you don't want to use two distinct queries, use one like this:
Query 1:
objects: Year, Sales ... etc.
filters: Year Equal to '1. Prompt Year'
Or
New Object Last Year Equal to '1.Prompt Year'
Edited by: PadawanGirl on Jun 23, 2011 6:28 PM -
Current Year and Previous Year (derived) data comparison
Scenario:
Dimension Table for Date:
-Current Year
-Previous Year
-and other date related fields
Fact Table:
-Sales (contains current year sales depending on the filter set)
*Filter on Year
Would anyone know how will I create a measure for Previous Year Sales?
So that whenever my report shows the current year (for example: 2009) data of my sales, I can also have a column that would also display the previous year data and it will automatically know that it would display the previous year data of the Current year displayed in my report.
Also, how to derive the percentage change of this 2 columns.
Year: 2009
Branch --- Current Year Sales (Sales from Fact table) 2009 --- Previous Year Sales 2008???
I want to add the Current Year Sales And Percentage Change of Sales in the Business Model/Mapping Section. so that it would be available in the presentation layer of Oracle Answers.
Thanks.
Edited by: user12074468 on Oct 16, 2009 4:38 PMUse column filters. Click on the fx button on your Sales column. Click on the Filter button. Now go to the Time.Year column you have and click on it. When the filter window comes up, click on Advanced and convert the filter to SQL. Now insert the Current Year column so that you have Time.Year = "Current Year" Click "OK."
Get another Sales column and put it in your workspace. Follow the above procedure except this time use th Previous Year column.
Now you have two Fact columns, one that filters for the Current Year and one that filters for your Previous Year.
Now for your variance, click on one more column and place it in your workspace. Click on the fx button. This time click on the "Column" button. You will see a list of your columns. From this, create the (Current Year)-(Previous Year)/(Previous Year)*100.00. In the Data Format tab, change the format to percentage.
You also have the option of creating the above calculations in the BMM layer too. -
Displying Current year and previoues year whlie selecting prompt level
Hi All,
we have year prompt and report level year column,fact1,Fact2(year Ago).
now when we select year value in prompt level we need to display that value and privoues year values.
Ex: if select 2011 in report level need to diplay the 2011,2010.
report factcolumn is working fine i need to disply the year values(like 2013,2012)
Find the image
http://s10.postimg.org/7jvc9svd5/image.png
Thanks,Hi,
What is your question? what is not working fine? You mean report or Prompt?
Thanks, -
Field over flow can not display the total and subtotal in ALV
hi
i am running a z report with huge data in quality system.
in 2 columns and not able to show the total and subtotal in 2 columns
it says field overflow and cannot be dispayed.
value is around 20character integer.You can create a domains with 20 positions and 2 decimal, for example.
Than, associate this domain a data element.
To finish assign that data element to the column you wanna sum.
I hope help. -
Need to sum hh:mm:ss in crystal report using Running Total Fields
Hello,
I am new to .Net and crystal reports so please go easy on me.
I am trying to develop a crystal report using Visual Basic .NET. I have a column which displays the "Inbound Time" in "hh:mm:ss" format. I have to sum the total inbound time and display it.
I tried using the Running Total and i am not successful.
Here is the code which I am using in the Running total
WhilePrintingRecords;
if isNumeric({Report3;1.TotalInboundTime}) then
{Report3;1.TotalInboundTime}
else
CStr ({Report3;1.TotalInboundTime});
NumberVar array test2 := [ToNumber(left(CStr({Report3;1.TotalInboundTime}),2)),ToNumber(mid(Cstr({Report3;1.TotalInboundTime}),4,2)),ToNumber(right(Cstr({Report3;1.TotalInboundTime}),2))];
StringVar test1 := CStr( (ToNumber(test2[1])3600)+(ToNumber(test2[2])60)+(ToNumber(test2[3])));
InboundTime is the time field which is in "hh:mm:ss" format.Hello Bharathi,
There are a couple of KBs about this. I haven't tested them myself, but you could give them a try:
[How sum multiple time fields in Crystal Reports|http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=c2008378]
[Creating a running total to show the difference between two datetime fields |http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=c2010261]
[Totalling time values that are stored as numbers in the database|http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=c2005576]
Cheers,
Fritz -
Running Total Variation Query Time Optimization
Hi all,
I've been struggling with this query for a while. I need to set a customer specific running total for 10 million rows (reset for every customer). But every time the number goes negative, I need to set it as zero.
For example,
member no amount wallet
member1 400 400
member1 -500 0
member1 200 200
member2 700 700
member2 -200 500
Query:
DECLARE @member float
DECLARE @prev_member float
DECLARE @amount float
DECLARE @wallet float
DECLARE db_cursor CURSOR FOR
SELECT [Member no], [Transaction Amount]
FROM [wallet_master_3]
ORDER BY [Member No], [rownum]
FOR UPDATE
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @member, @amount
SET @prev_member = @member
set @wallet=0
WHILE @@FETCH_STATUS = 0
BEGIN
IF @prev_member <> @member set @wallet=0
SET @wallet = @wallet + @amount
IF @wallet < 0 SET @wallet = 0
UPDATE [wallet_master_3] SET walletsize = @wallet
WHERE CURRENT OF db_cursor
set @prev_member=@member
FETCH NEXT FROM db_cursor INTO @member, @amount
END
CLOSE db_cursor
DEALLOCATE db_cursor
I've tried using a cursor. In five minutes, it ran 17,000 rows but after running it for 15 hours, the code only manages to set the running total for 175,000 rows. I'm not exactly sure why. Is there a faster approach I can use?
Thanks!As an exercise a 'Quirky Update' may help you in this scenario. Try the below trick!
DECLARE @Wallet AS TABLE
MemberNo VARCHAR(10),
RowNum INT,
Amount INT,
Wallet INT
INSERT INTO @Wallet (MemberNo, RowNum, Amount) VALUES
('member1',1, 400),
('member1',2, -500),
('member1',3, 200),
('member2',1, 700),
('member2',2, -200)
DECLARE @RunTotal AS INT
UPDATE W1
SET
@RunTotal = W1.Wallet =
CASE
WHEN W1.RowNum = 1 THEN W1.Amount
WHEN @RunTotal + COALESCE(W1.Amount, W2.Amount) < 0 THEN 0
ELSE @RunTotal + COALESCE(W1.Amount, W2.Amount)
END
FROM @Wallet W1
LEFT OUTER JOIN @Wallet W2
ON W1.MemberNo = W2.MemberNo AND W2.RowNum = W1.RowNum - 1;
SELECT * FROM @Wallet;
RESULT
MemberNo RowNum Amount Wallet
member1 1 400 400
member1 2 -500 0
member1 3 200 200
member2 1 700 700
member2 2 -200 500
You can read more on 'Quirky Update' in below articles
Solving the Running Total and Ordinal Rank Problems - Jeff Moden
Robyn Page's SQL Server Cursor Workbench
NOTE: Please test it thoroughly before using in a production environment!
Krishnakumar S
Maybe you are looking for
-
IMovie to iPod - what is the highest resolution setting possible?
I'm creating an iMovie and i want to save it to my 30gb video ipod, and then play it back on a lcd projector to a 12 foot screen (for a presentation in a room full of people). If i use the standard 320x240 resolution, i'm pretty sure it will look ver
-
Auto update of file from laptop to ipad?
Does anyone know if I sync an existing document from my laptop to my ipad via pages, then work on it on the ipad, will it update the existing file on the laptop when I sync overall?
-
Clever ways to propogate the correct IP addy?
OK, so I got my wrp400 working mostly. The problem I am still facing is that incoming calls still have one way audio. They can hear me, I cannot hear them... so after a bit of search and testing and reading and manipulating, I found that this worked:
-
Anyone considering switching to a macbook due to fusteration?
I've never been an apple guy but I've had the lenovo yoga 2 pro for less than a year and have gone through many issues. CONS- - recently wouldn't turn on, even after a hard reset the screen kept freezing. Contacted Lenovo and they issued me an RMA
-
Does anyone have any details about Wi-Fi- DAQ?
Hello Everyone, Does anybody know how to use the Wifi DAQ?? Do I need a wireless network already set up where I should place this wifi DAQ and then use it? I see the protocol is 802.11 b/g... so, would it require a modem/router