Update field taking value from previous row
I have a table TEST (ID int, name varchar(20), amount decimal(18,0)).
First row of the table have correct value. I want to update amount column except first row by adding 10 with the previous row value without using cursor.
id Name Amount
1 abc 10
2 def 15
3 ghi 20
4 jkl 22
5 mno 25
6 pqr 27
7 stu 30
8 vwx 33
id Name Amount
1 abc 10
2 def 20
3 ghi 30
4 jkl 40
5 mno 50
6 pqr 60
7 stu 70
8 vwx 80
please help me.
thanks
srimanta manna
create table #t (id int, amount int)
insert into #t values (1,10)
insert into #t values (2,25)
insert into #t values (3,46)
insert into #t values (4,55)
insert into #t values (5,160)
insert into #t values (6,89)
insert into #t values (7,100)
with cte
as
select *,(select min(amount) from #t t where t.id=1) as a
FROM #t
) update #t set amount=(select sum(a) from cte c where c.id<=cte.id)
from cte where #t.id=cte.id
select * from #t
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
Sum of Values from previous rows in a dynamic table
Hello,
I have a dynamic table has multiple rows (added dynamically via a button). One column in the table is a Quantity column. Another is a Total column. We do not want to keep a running total, but only wish to display a total when the rest of the cells in that row are emty and the previous row(s) has/have values in the Quantity column. The Total is the sum on the Quatnities up to a blank row. Below is a sample. How do I get teh value of the Quantities in the previous rows?
Quantity
Total
5
8
12
25
7
27
34
22
22
Another option might be to put the Total in the last row with data as opposed to the row below the data.
Any ideas?
Regards,
KarlThe script is written to achive your requirement (i.e. the second approach you have mentioned)
You can either contact me at [email protected] to get the sample form created.
Or the following is the XML Source of the form. Copy the entire content in XML source view of your form and see the result.
<?xml version="1.0" encoding="UTF-8"?>
<?xfa generator="AdobeLiveCycleDesignerES_V9.0.0.0.20091029.1.612548" APIVersion="3.1.9277.0"?>
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2012-02-28T14:04:54Z" uuid="2c561cdf-3377-4e84-9a89-51e740bb2fea">
<template xmlns="http://www.xfa.org/schema/xfa-template/2.8/">
<?formServer defaultPDFRenderFormat acrobat9.0dynamic?>
<subform name="form1" layout="tb" locale="en_US" restoreState="auto">
<pageSet>
<pageArea name="Page1" id="Page1">
<contentArea x="0.25in" y="0.25in" w="197.3mm" h="284.3mm"/>
<medium stock="a4" short="210mm" long="297mm"/>
<?templateDesigner expand 1?></pageArea>
<?templateDesigner expand 1?></pageSet>
<subform w="197.3mm" layout="tb">
<subform name="Subform1" w="190.5mm" h="25.4mm">
<field name="Button1" y="15.875mm" x="60.325mm" w="28.575mm" h="6mm">
<ui>
<button highlight="inverted"/>
</ui>
<font typeface="Myriad Pro"/>
<caption>
<value>
<text>Add Row</text>
</value>
<para vAlign="middle" hAlign="center"/>
</caption>
<border hand="right">
<?templateDesigner StyleID apbx2?>
<edge stroke="raised"/>
<fill/>
</border>
<bind match="none"/>
<event activity="click" name="event__click">
<script contentType="application/x-javascript">
try
Subform2.Table1._Row1.addInstance(1);
//for(var i=0;i<Subform2.Table1._Row1.count;i++)
//xfa.resolveNode("Subform2.Table1.Row1["+i+"].Total").execEvent("exit");
}catch(e)
app.alert(e)
</script>
</event>
</field>
<?templateDesigner expand 1?></subform>
<subform name="Subform2" w="196.85mm">
<subform name="Table1" layout="table" columnWidths="55.916mm 44.47mm" x="38.1mm" y="12.7mm">
<border>
<edge/>
</border>
<subform layout="row" name="HeaderRow" id="HeaderRow_ID">
<assist role="TH"/>
<draw h="10mm" name="Cell1">
<border>
<edge/>
<corner thickness="0.1778mm"/>
</border>
<ui>
<textEdit/>
</ui>
<value>
<text>Quantity</text>
</value>
<font typeface="Myriad Pro"/>
<margin topInset="0.5mm" bottomInset="0.5mm" leftInset="0.5mm" rightInset="0.5mm"/>
<para vAlign="middle" hAlign="center"/>
</draw>
<draw h="10mm" name="Cell2">
<border>
<edge/>
<corner thickness="0.1778mm"/>
</border>
<ui>
<textEdit/>
</ui>
<value>
<text>Total</text>
</value>
<font typeface="Myriad Pro"/>
<margin topInset="0.5mm" bottomInset="0.5mm" leftInset="0.5mm" rightInset="0.5mm"/>
<para vAlign="middle" hAlign="center"/>
</draw>
<border>
<edge presence="hidden"/>
</border>
<occur max="-1"/>
<?templateDesigner expand 1?></subform>
<subform layout="row" name="Row1">
<assist role="TR"/>
<field name="Quantity" w="55.916mm" h="9.317mm">
<ui>
<numericEdit>
<border presence="hidden">
<?templateDesigner StyleID aped0?></border>
<margin/>
</numericEdit>
</ui
><
font typeface="Myriad Pro"/><
margin topInset="1mm" bottomInset="1mm" leftInset="1mm" rightInset="1mm"/><
para vAlign="middle"/><
border><
edge/><
corner thickness="0.1778mm"/></
border></
field><
field name="Total" w="44.47mm" h="9.317mm" access="readOnly"><
ui><
numericEdit><
border presence="hidden">
<?templateDesigner StyleID aped0?>
</border><
margin/></
numericEdit></
ui><
font typeface="Myriad Pro"/><
margin topInset="1mm" bottomInset="1mm" leftInset="1mm" rightInset="1mm"/><para vAlign="middle"/>
<border>
<edge/>
<corner thickness="0.1778mm"/>
</border>
<calculate>
<script contentType="application/x-javascript">
try
var nextRow = xfa.resolveNode("Subform2.Table1.Row1["+(this.parent.instanceIndex+1)+"]"); // Next row of the table
if((nextRow==null || nextRow.Quantity.rawValue == null || nextRow.Quantity.rawValue=="") && Quantity.rawValue!=null) // If there is no more rows OR the next row don't contain any Quantity value
var subTotal = 0;
for(var j=this.parent.instanceIndex;j>=0;j--) // Loop until the previous row has empty value OR reach start of row Index (i.e. 0)
var prevObj = xfa.resolveNode("Subform2.Table1.Row1["+j+"].Quantity"); // locate the previous row's Quantity object
if(prevObj.rawValue == null || prevObj.rawValue=="")
break; // if blank value found, skip the loop
subTotal+= prevObj.rawValue;
this.rawValue = subTotal; // Update the Total value
}else
this.rawValue = null; // Clear the total value
}catch(e)
app.alert(e)
</script>
</calculate>
</field>
<border>
<edge presence="hidden"/>
</border>
<occur max="-1"/>
<?templateDesigner expand 1?></subform>
<keep intact="contentArea"/>
<?templateDesigner rowpattern first:1, next:1, firstcolor:f0f0f0, nextcolor:ffffff, apply:0?>
<overflow leader="HeaderRow"/>
<?templateDesigner expand 1?></subform>
<?templateDesigner expand 1?></subform>
<?templateDesigner expand 1?></subform>
<proto/>
<desc>
<text name="version">9.0.0.0.20091029.1.612548.606130</text>
</desc>
<?templateDesigner expand 1?></subform>
<?templateDesigner DefaultPreviewDynamic 1?>
<?templateDesigner DefaultRunAt client?>
<?templateDesigner Grid show:1, snap:1, units:0, color:ff8080, origin:(0,0), interval:(125000,125000)?>
<?templateDesigner FormTargetVersion 28?>
<?templateDesigner DefaultLanguage JavaScript?>
<?acrobat JavaScript strictScoping?>
<?templateDesigner Zoom 62?>
<?templateDesigner Rulers horizontal:1, vertical:1, guidelines:1, crosshairs:0?>
<?templateDesigner SaveTaggedPDF 1?>
<?templateDesigner SavePDFWithEmbeddedFonts 1?></template>
<config xmlns="http://www.xfa.org/schema/xci/2.8/">
<agent name="designer">
<!-- [0..n] -->
<destination>pdf</destination>
<pdf>
<!-- [0..n] -->
<fontInfo/>
</pdf>
</agent>
<present>
<!-- [0..n] -->
<pdf>
<!-- [0..n] -->
<fontInfo/>
<version>1.7</version>
<adobeExtensionLevel>3</adobeExtensionLevel>
</pdf>
<xdp>
<packets>*</packets>
</xdp>
</present>
</config>
<localeSet xmlns="http://www.xfa.org/schema/xfa-locale-set/2.7/">
<locale name="en_US" desc="English (United States)">
<calendarSymbols name="gregorian">
<monthNames>
<month>January</month>
<month>February</month>
<month>March</month>
<month>April</month>
<month>May</month>
<month>June</month>
<month>July</month>
<month>August</month>
<month>September</month>
<month>October</month>
<month>November</month>
<month>December</month>
</monthNames>
<monthNames abbr="1">
<month>Jan</month>
<month>Feb</month>
<month>Mar</month>
<month>Apr</month>
<month>May</month>
<month>Jun</month>
<month>Jul</month>
<month>Aug</month>
<month>Sep</month>
<month>Oct</month>
<month>Nov</month>
<month>Dec</month>
</monthNames>
<dayNames>
<day>Sunday</day>
<day>Monday</day>
<day>Tuesday</day>
<day>Wednesday</day>
<day>Thursday</day>
<day>Friday</day>
<day>Saturday</day>
</dayNames>
<dayNames abbr="1">
<day>Sun</day>
<day>Mon</day>
<day>Tue</day>
<day>Wed</day>
<day>Thu</day>
<day>Fri</day>
<day>Sat</day>
</dayNames>
<meridiemNames>
<meridiem>AM</meridiem>
<meridiem>PM</meridiem>
</meridiemNames>
<eraNames>
<era>BC</era>
<era>AD</era>
</eraNames>
</calendarSymbols>
<datePatterns>
<datePattern name="full">EEEE, MMMM D, YYYY</datePattern>
<datePattern name="long">MMMM D, YYYY</datePattern>
<datePattern name="med">MMM D, YYYY</datePattern>
<datePattern name="short">M/D/YY</datePattern>
</datePatterns>
<timePatterns>
<timePattern name="full">h:MM:SS A Z</timePattern>
<timePattern name="long">h:MM:SS A Z</timePattern>
<timePattern name="med">h:MM:SS A</timePattern>
<timePattern name="short">h:MM A</timePattern>
</timePatterns>
<dateTimeSymbols>GyMdkHmsSEDFwWahKzZ</dateTimeSymbols>
<numberPatterns>
<numberPattern name="numeric">z,zz9.zzz</numberPattern>
<numberPattern name="currency">$z,zz9.99|($z,zz9.99)</numberPattern>
<numberPattern name="percent">z,zz9%</numberPattern>
</numberPatterns>
<numberSymbols>
<numberSymbol name="decimal">.</numberSymbol>
<numberSymbol name="grouping">,</numberSymbol>
<numberSymbol name="percent">%</numberSymbol>
<numberSymbol name="minus">-</numberSymbol>
<numberSymbol name="zero">0</numberSymbol>
</numberSymbols>
<currencySymbols>
<currencySymbol name="symbol">$</currencySymbol>
<currencySymbol name="isoname">USD</currencySymbol>
<currencySymbol name="decimal">.</currencySymbol>
</currencySymbols>
<typefaces>
<typeface name="Myriad Pro"/>
<typeface name="Minion Pro"/>
<typeface name="Courier Std"/>
<typeface name="Adobe Pi Std"/>
<typeface name="Adobe Hebrew"/>
<typeface name="Adobe Arabic"/>
<typeface name="Adobe Thai"/>
<typeface name="Kozuka Gothic Pro-VI M"/>
<typeface name="Kozuka Mincho Pro-VI R"/>
<typeface name="Adobe Ming Std L"/>
<typeface name="Adobe Song Std L"/>
<typeface name="Adobe Myungjo Std M"/>
</typefaces>
</locale>
</localeSet>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.398682, 2009/08/10-13:00:47 ">
<
rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><
rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about=""><
xmp:MetadataDate>2012-02-28T14:04:54Z</xmp:MetadataDate><
xmp:CreatorTool>Adobe LiveCycle Designer ES 9.0</xmp:CreatorTool></
rdf:Description><
rdf:Description xmlns:pdf="http://ns.adobe.com/pdf/1.3/" rdf:about=""><
pdf:Producer>Adobe LiveCycle Designer ES 9.0</pdf:Producer></
rdf:Description><
rdf:Description xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" rdf:about=""><
xmpMM:DocumentID>uuid:2c561cdf-3377-4e84-9a89-51e740bb2fea</xmpMM:DocumentID></
rdf:Description><
rdf:Description xmlns:desc="http://ns.adobe.com/xfa/promoted-desc/" rdf:about=""><
desc:version rdf:parseType="Resource"><
rdf:value>9.0.0.0.20091029.1.612548.606130</rdf:value><
desc:ref>/template/subform[1]</desc:ref></
desc:version></
rdf:Description></
rdf:RDF></
x:xmpmeta></xdp:xdp> -
SQL Developer - Pulling column value from previous row
I am using Oracle SQL developer and trying to pull a value from a column from the previous row.
Currently this is an example from the code im using.
Select CD1.nbr_dw, CD1.SEQ_DW, CD1.CDL_NET_PAID, CD1.UNITS_ALLOW,CD1.ALLOW_AMT, CD1.UNIT_PRICE, CD1.BACKED_OUT,
case
When CD1.NET_PAID = 0 then 0
****NEW CODE*****
Else CD1.ALLOW_AMT / CD1.UNIT_PRICE
end as NEW_UNITS
From Table_A CD1
join (Select nbr_dw, DET_DW, SEQ_DW
From Table_B
) CD2
on CD1.nbr_dw = CD2.nbr_dw
I need to add another when statement that says when CD1.BACKED_OUT = 'Y' populated the NEW_UNITS field with the previous rows value of CD1.UNIT_PRICE. Note, the CD1.SEQ_DW can be used to determine the previous row. Any ideas?Hi,
Welcome to the forum!
The analytic LAG function can return a value from the previous row:
LAG (cd1.unit_price) OVER ( -- PARTITION BY x -- if needed
ORDER BY cd1.seq_dw
)It's unclear if you need a PARTITION BY clause or not.
"PARTITION BY x" means that you want the value from the last row that has the same value of x as the current row.
If you omit the PARTITION BY clause, it means you want the last row regardless of what any other columns are.
Whenever you have a problem, it ehlps if you post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
Explain how you get those results from that data.
Always say what version of Oracle you're using. -
Expanding table: Calculating difference to value from previous row
Hi there,
I am a complete newbie to LiveCycle Designer (ES2) and have created below document with an expanding table.
Shared Files - Acrobat.com
My aim is to make the form user friendly by adding a calculation in the field "Twist" which calculates the difference from the current row to the previous row.
I have no idea about Java Script, I am afraid, and also don't know if this is possible at all so it's probably a bad idea after all.
The reason for setting it up as an expanding table is so that the form can be used for all 32 instances the form would be used for (they would all require different amount of rows altogether).
The calculation would start in row 2 (Checklist.Table1), take the twist value entered in row 2 and calculate the difference to the twist value entered in row 1.
Then in row 3, it would calculate the difference between twist value in row 3 to row 2 etc.
So subtract value of field in rown with value in rown-1 or something in this direction.
Is there anyone at all who could help me with this at all?
I'd be very grateful for any advice you could give me.
Thanks a lot!
MathildaNot sure what happened with the formatting there, try this;
if (Row1.index > 0 && !Row1.resolveNode("NumericField4[0]").isNull)
var prevTwist = Table1.resolveNode("Row1[" + (Row1.index - 1) + "].NumericField4[0]").rawValue
var result = Math.abs(3000 / (Row1.resolveNode("NumericField4[0]").rawValue - prevTwist));
this.rawValue = result;
else
this.rawValue = ""; -
Update Nulls With Value from Another Row
Good Morning,
I word for a car manufacturer. I am pulling an excel spreadsheet into SQL 2012.The spreadsheet lists one line for each dealer, each carline. So if there are 6 carlines and 65 dealers there will be 390 lines. when the spreadsheet gets to me it looks like
this:
Dealer
Carline District Data Data Data
East Side Craworld Model1
1 0
0
Model2
1 0 0
Model3
1 0
0 0
So the Dealer is only listed once. When I pull this into SQL the blank lines are nulls and I want them to be the Dealer name in there. How can I accomplish this with an update.
Just one thing more. When I programmed in access, I would loop through a table and set a variaiable =Dealer name and not change the variable until the next not null row and then make that the new variable all the while making nulls=the variable. Is there
a way to accomplish that here.The only issue is this file will eventually be a feed and an ftp agent will grab the feed place it somewhere and and there will be a stored package to import it.
Can I do an update on a null field with the field from the previous record, or am I dealing witht he ordering thing again. I found this code. Will it work?
select Date
, GroupId
, case
when Comment is not null then Comment
else
select Comment
from YourTable yt2
where yt1.GroupId = yt2.GroupId
and yt2.Comment is not null
and yt2.Date < yt1.Date
and not exists
select *
from YourTable yt3
where yt1.GroupId = yt2.GroupId
and yt2.Comment is not null
and yt3.Date < yt2.Date and yt2.Date < yt1.Date
) end as Comment
from YourTable yt1 -
Getting previous value from previous row
Hi,
My desired output should be
ID Book_date Credit Previous_Credit
123IT1 12/8/2008 100800 72500
from this table:
ID Book date Credit
123IT1 12/8/2008 100800
123IT1 12/18/2007 72500
123IT1 11/14/2006 150720
I tried to use the lead function but I'm having problem when I included the date range condtion:
This is my query:
select id, book_date, credit, lead(credit) over (order by rownum) as previous_credit
from t
where book_date between '01-December-2008' and '31-December-2008'
Result
ID Book_date Credit Previous_Credit
123IT1 12/8/2008 100800
The previous_credit column is always blank. I think because of the date range..?
Any idea how to get the right result? pls. helpYour expected output indicates that you may require a LAG
SQL> with t as
2 (
3 select '123IT1' id, to_date('12/08/2008','mm/dd/yyyy') Book_Date, 100800 Credit from dual uni
on
4 select '123IT1', to_date('12/18/2007','mm/dd/yyyy'), 72500 from dual union
5 select '123IT1', to_date('11/14/2006','mm/dd/yyyy'), 150720 from dual
6 )
7 --
8 select id
9 ,Book_Date
10 ,Credit
11 ,lag(Credit) over (partition by id order by Book_Date) Previous_Credit
12 from t
13 /
ID BOOK_DATE CREDIT PREVIOUS_CREDIT
123IT1 14-NOV-06 150720
123IT1 18-DEC-07 72500 150720
123IT1 08-DEC-08 100800 72500If you always require a Previous Credit then you may want to modify this:
(partition by id order by Book_Date)to this:
(order by id, Book_Date) -
How to get the value of column from previous row to current row?
Hi All,
I am facing a critical problem in SQL query (for reporting purpose (COGNOS)). please reply to my query.
REQUIREMENT: i want to retrive value of a column (this is not a table column, this will be calculated based expression) from previous row to current row.
EXAMPLE:
TABLE NAME: i have to join multiple tables. so, i am not mentioning table names here.
DISPLAY COLUMNS in the report: item, loc, sku, beginval (not table column), endval (not table column, this will calculated based on some expressions), etc. Here, first time the value of BEGINVAL will be taken from some x column name of x table. ENDVAL will calculated based on the expression. For the next row onwards, BEGINVAL will become the value of ENDVAL and the value of ENDVAL will be calculated based on the expression and this expression uses the value of BEGINVAL.
my report will look like below.
ITEM LOC SKU BEGINVAL ENDVAL
1 HYD 1-HYD 10 10+1+2 (13)
2 HYD 2-HYD 13 13+1+2 (16)
3 SEC 3-SEC 16 16+1+2 (19)
4 SEC 4-SEC 19 19+1+2 (22)
etc....
in the above output, BEGINVAL and ENDVAL columns are not part of any table. they are alias column names.if you observe intially BEGINVAL will be assigned to some value, but from subsequent rows, BEGINVAL will become the ENDVAL of previous row.
Please help me on how to write this query?Hi, please find the detail description of the problom.
DDL (table scripts)
ITEM
CREATE TABLE ITEM
ITEM VARCHAR2(50 CHAR) NOT NULL,
DESCR VARCHAR2(50 CHAR) DEFAULT ' ' NOT NULL,
UOM VARCHAR2(50 CHAR)
SKU
CREATE TABLE SKU
ITEM VARCHAR2(50 CHAR) NOT NULL,
LOC VARCHAR2(50 CHAR) NOT NULL,
OH float
SKUPROJSTATIC
CREATE TABLE SKUPROJSTATIC
ITEM VARCHAR2(50 CHAR) NOT NULL,
LOC VARCHAR2(50 CHAR) NOT NULL,
STARTDATE DATE
VehicleLoad
CREATE TABLE VEHICLELOAD
LOADID VARCHAR2(50 CHAR) NOT NULL,
DESCR VARCHAR2(50 CHAR) DEFAULT ' ' NOT NULL,
SHIPDATE DATE DEFAULT TO_DATE('01/01/1970','MM/DD/YYYY') NOT NULL,
ARRIVDATE DATE
VEHICLELOADLINE
CREATE TABLE VEHICLELOADLINE
LOADID VARCHAR2(50 CHAR) NOT NULL,
ITEM VARCHAR2(50 CHAR) NOT NULL,
QTY float(126)
DML scripts
I can't provide the the DML scripts, because its very huge data.
Main QUERY is below.
below is the query which i have to write and execute.
select
i.item,
i.descr,
i.unitsperpallet,
sp.loc,
sp.startdate,
'Crucial_IND',
LAG (EndBal,1,0) OVER (ORDER BY STARTDATE) BeginBal,
SP.FCSTCUSTORDERS CustOrders,
SP.COMMITINTRANSOUT,
SP.RECARRIV,
SP.TOTINTRANSIN,
(BeginBal - sp.FCSTCUSTORDERS - sp.COMMITINTRANSOUT + sp.TOTINTRANSIN ) EndBal,
'CuttingQty',
VLL.QTY,
vl.source,
vl.arrivdate,
vl.shipdate,
vl.loadid,
s.oh
from item i, skuprojstatic sp, sku s, VehicleLoad vl, VehicleLoadLine vll
where sp.item = i.item
and s.item=i.item
and sp.item =s.item (+)
and sp.loc = s.loc (+)
and vll.item = s.item
and vll.loadid = vl.loadid
and to_char(sp.startdate ,'mm/dd/yyyy') = to_char(vl.arrivdate,'mm/dd/yyyy')
and sp.loc = vl.dest (+)
order by sp.startdate
problem description: in the above query, BeginBal and EndBal is what i am looking for. when i execute this query, oracle throwing an error saying that alias names can't be used as expressions. For the first row, the BeginBal should be the value sku.OH and for the subsequent rows, this value will be the previous row value of EndBal. -
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
Get values from selected row in a Table?
Hello.
I'm on VC 7.1 (the trial version downloaded from SDN).
I'm trying to figure out a way to retrieve some values from the currently selected row in a Table element through the output connector.
I have a web-service which returns results to the Table, and I want the user to be able to select one of the rows and then trigger another web-service call with some of the values from that row -- is this possible?
Also, I can't find any documentation that lists what can and can't be done with each UI element, is there something like this some where? (the Modeler's guide doesn't help, and the Reference guide seems to focus on menu items and what the VC screen looks like)
Thanks,
AlonHi Alon
This is a very simple task.
You just need drag the service which you want to execute, after select row, in model.
Drag output connector from table to input connector of service. Then map the parameter.
Regards
Marcos -
How do I update a bean value from an AJAX call?
Hi all,
How do I update a bean value from an AJAX call? I suppose I could write a servlet to do it. However, this seems like a common problem, so I was wondering if there was some built in solution.
Thanks,
Grae
Edited by: caalip2 on Mar 30, 2010 1:07 PMcaalip2 wrote:
Raymond
Basically, I would user the following. The first choice for IE, the second for Firefox.
new ActiveXObject("Microsoft.XMLHTTP");
new XMLHttpRequest();
GraeDon't do this to yourself. If it were that easy there wouldn't be AJAX frameworks for JSF. Find one you like and use it. I've used a4j (part of RichFaces) successfully. -
Condition value from previous PO changes total value of new PO
Dear gentlemen,
We have a surcharge condition, calculation type = B (Fixed amount), category = Delivery costs. When viewing header condition details in PO, there appears an unknown "condition base value" with no "rate unit" associated with it. This value is carried over to the next PO created, changing its total value, thus affecting inventory value. What is wrong with this condition? How can I not let the system carry over "condition value" from previous POs?
Regards,
Carlos Piana
La Universal
Guayaquil, Ecuador, South AmericaMy aim is the difference between 56062 on 10.07.2012 00:00:00 and 52013 on 13.04.2012 and so on.
The final table should look like this:
DateId
Severity
PageCount
DeviceId
ErrorId DIFF
13.04.2012 00:00:00
1
52013
163
1 52013
10.07.2012 00:00:00
1
56062
163
1 4049
13.11.2012 00:00:00
4
63907
163
1 ...
28.11.2012 00:00:00
4
64492
163
1
12.09.2012 00:00:00
4
61524
163
1
29.11.2012 00:00:00
4
64573
163
1
Why I am doing this is that I want to calculate an Printerindex. This is the Amount of Errors related to the volume of pages, printed.
The Formula in DAX is Measure:=(COUNT(FactErrors[ErrorId]))/(SUM(FactErrors[PagesCount])/10000)
So I get this PivotTable:
Zeilenbeschriftungen
CountDevices
SUM PageCount
CountErrors
PrinterIndex
MFP
523
90135296
1362
31,24906792
HP
125
30805190
241
5,529387202
Lexmark
369
53500358
856
27,39392853
Samsung
29
5829748
265
41,33069233
Samsung CLX-92x1 93x1 Series
22
5400624
246
38,36735967
Samsung SCX-8123 8128 Series
7
429124
19
4,482612183
You see, that if I can't SUM already summarized printed volume. Another way could be to aggregate the volume as MAX() but this is not working, either.
Zeilenbeschriftungen
CountDevices
MAX PageCount
CountErrors
PrinterIndex
MFP
523
435853
1362
0,151106177
HP
125
435853
241
0,07823357
Lexmark
369
312478
856
0,159998929
Samsung
29
64117
265
0,454565103
Samsung CLX-92x1 93x1 Series
22
64117
246
0,45550292
Samsung SCX-8123 8128 Series
7
42386
19
0,442762465
I hope you see my problem ... -
Attribute value of previous row
Hi
I have a read only VO.
I need attribute value of previous row .
how can i get it ?
consider these 3 attributes and their values :
Id ** add ** sum
1 *** 10 *** 10 -- > (value of previous sum + new value of add)
2 *** 20 *** 10 + 20 = 30 -- > (value of previous sum + new value of add)
3 *** 30 *** 30 + 30 = 60 -- > (value of previous sum + new value of add)
now , i write a method in impl and call this method in page def by invoke action .
i used Row[] rows = this.getViewObject().getAllRowsInRange(); in my method.
but i am looking for better solution.Hi,
If you wanted to do a running total like that, you could certainly use analytics to do that in the SQL statement itself (provided you're using an Oracle database). use SUM() over ()...
John -
How to populate field on page with Primary Key value from previous page
I am trying to create a patient tracking system for a group of doctors. There is an add patient form based on the Patient table (which has Patient_Id as its primary key) which branches to a pre-operative assessment form. I would like to populate the pre-op assessment Patient_Id field with the Patient_Id generated by the Add Patient page during processing, which comes from the Patient_seq sequence. How can I do this? I have tried using a computation on the Pre-Op Assessment form, but no matter what I put in, the field remains blank.
Hi,
If I understand you correctly, once patient record is created you branching to next page (pre-operative assessment form). First create a static hidden item in patient form *:PX_PATIENT_ID_COPY*.
Create an On submit after computation and validation process in patient form to get the inserted patient_id from patient table. Here is the code -
SELECT patient_id into :PX_PATIENT_ID_COPY from patient_table where rownum=1
order by patient_id descI would not use the sequence to get the current value because if the inserted record been deleted from your patient table, sequence current value would not be valid to find that record in patient table.
Basically when the record been inserted, the process get the value and put into the hidden item.
Pass the value from the hidden item to the next page by setting them in page branch. Under the Action section in the page branch, Set this items field type - *:PX_PATIENT_ID* (next page item for patient_id). Type *&PX_PATIENT_ID_COPY.* in the with these values field. Make sure you include dot(.) after *&PX_PATIENT_ID_COPY*.
Give it a try now. Hope it would helps.
Regards,
Tajuddin
Blog: http://aspblog.whitepagesbd.com
web: http://tajuddin.whitepagesbd.com -
I have a SSRS report which uses a matrix for a crosstab effect.
Each row contains about 10 score values in 10 columns respectively. I need each row to check against the previous row, and i need each score value in each column to be compared to the corresponding column score value in the previous row.
If the current score is greater than the corresponding previous score (in the previous row), then i want to change the background of the cell.
if the current score is smaller than the previous, then it's a different color.
if they are equal, or it's the first row in the matrix table, then leave white.
I have found custom code functions to use in the SSRS expression fields, but every single one of them compares against the previous COLUMN value and not the previous ROW value which is what i need. the "Previous" function would be perfect if i
could use it in a matrix but i can't. (i keep getting error "The use of a Previous aggregate function in a tablix cell is not supported"). looking around it turns out that matrices are arrange in groups and not in rows which is why Previous can't
be used and the only way is with custom code.
Please help. if you have any custom code samples that achieve what i need, please share, or give me advice on how to achieve this.
Thank youI figured it out. Maybe it can help someone else in the future:
Public Shared count as Integer = 0
Public Shared currentRow As Integer = 1
Public Shared MatrixStructures As New System.Collections.Generic.List(Of MatrixStructure)()
Public Shared Function GetCellColor(row as Integer, score as Integer)
If (row > currentRow) Then
count = 0
currentRow = row
End If
count = count + 1
Dim matrixStructure As New MatrixStructure()
matrixStructure.RowIndex = row
matrixStructure.ColumnIndex = count
matrixStructure.ScoreValue = score
MatrixStructures.Add(matrixStructure)
If score = 0 Then
Return "White"
End If
Dim val As MatrixStructure = MatrixStructures.Find(Function(s As MatrixStructure)
Return s.GetRowIndex() = row - 1 AndAlso s.GetColumnIndex() = count
End Function)
If (Not (val Is Nothing)) Then
If val.scoreValue = 0 Then
Return "White"
End If
If score >= val.scoreValue + 2 Then
Return "Green"
ElseIf score <= val.scoreValue - 2 Then
Return "Red"
End If
End If
Return "White"
End Function
Public Class MatrixStructure
Public rowIndex As Integer
Property GetRowIndex() As Integer
Get
Return rowIndex
End Get
Set(ByVal Value As Integer)
rowIndex = Value
End Set
End Property
Public columnIndex As Integer
Property GetColumnIndex() As Integer
Get
Return columnIndex
End Get
Set(ByVal Value As Integer)
columnIndex = Value
End Set
End Property
Public scoreValue As Integer
Property GetScoreValue () As Integer
Get
Return scoreValue
End Get
Set(ByVal Value As Integer)
scoreValue = Value
End Set
End Property
End Class
and to pass the current row number from the expression i use this
Ceiling(RowNumber(NOTHING) / 10)
i divide the row number by 10 because there are ten columns. if you don't know the number of columns, or it's a variable number, then return it from the stored procedure query in the first place. that's what I had to do -
Copying values from a row to a current row
hi all, i have a complex scenario here. i have a table that has the following data.
WITH table1 AS
SELECT 111 the_id, To_Date('6/30/2009','mm/dd/yyyy') dt, 93 src, 'A-C' the_name, 'AA' cod, 'BB' pad, ' CC' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/1/2009','mm/dd/yyyy') dt, 93 src, 'B-L' the_name, 'AA' cod, 'NN' pad, ' TT' tek FROM dual UNION all
SELECT 111 the_id, To_Date('10/2/2009','mm/dd/yyyy') dt, 93 src, 'C-H' the_name, 'BA' cod, 'RR' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/5/2009','mm/dd/yyyy') dt, 93 src, 'D-R' the_name, 'HH' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/6/2009','mm/dd/yyyy') dt, 93 src, 'E-C' the_name, 'JJ' cod, 'EE' pad, ' JJ' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/7/2009','mm/dd/yyyy') dt, 93 src, 'F-L' the_name, 'DD' cod, null pad, ' BAN' tek FROM dual UNION all
SELECT 111 the_id, To_Date('10/8/2009','mm/dd/yyyy') dt, 93 src, 'G-H' the_name, 'HG' cod, 'YY' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/9/2009','mm/dd/yyyy') dt, 93 src, 'K-R' the_name, 'EE' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('7/31/2009','mm/dd/yyyy') dt, 93 src, 'G-H' the_name, 'HG' cod, 'YY' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('8/3/2009','mm/dd/yyyy') dt, 93 src, 'K-R' the_name, 'EE' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('8/4/2009','mm/dd/yyyy') dt, 93 src, 'K-R' the_name, 'EE' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('8/5/2009','mm/dd/yyyy') dt, 93 src, 'K-R' the_name, 'EE' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('8/6/2009','mm/dd/yyyy') dt, 93 src, 'K-R' the_name, 'EE' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('8/7/2009','mm/dd/yyyy') dt, 93 src, 'K-R' the_name, 'EE' cod, 'FCY' pad, null tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('6/30/2009','mm/dd/yyyy') dt, 22 src, 'A-C' the_name, 'AA' cod, 'BB' pad, ' CC' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/1/2009','mm/dd/yyyy') dt, 22 src, 'B-L' the_name, 'AA' cod, 'NN' pad, ' TT' tek FROM dual UNION all
SELECT 111 the_id, To_Date('10/2/2009','mm/dd/yyyy') dt, 22 src, 'C-H' the_name, 'BA' cod, 'RR' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/5/2009','mm/dd/yyyy') dt, 22 src, 'D-R' the_name, 'HH' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/6/2009','mm/dd/yyyy') dt, 22 src, 'E-C' the_name, 'JJ' cod, 'EE' pad, ' JJ' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/7/2009','mm/dd/yyyy') dt, 22 src, 'F-L' the_name, 'DD' cod, 'FIC' pad, ' BAN' tek FROM dual UNION all
SELECT 111 the_id, To_Date('10/8/2009','mm/dd/yyyy') dt, 22 src, 'G-H' the_name, 'HG' cod, 'YY' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/9/2009','mm/dd/yyyy') dt, 22 src, 'K-R' the_name, 'EE' cod, 'FCY' pad, ' BANW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('10/30/2009','mm/dd/yyyy') dt, 168 src, 'T-C' the_name, 'WW' cod, 'AA' pad, ' NN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('11/2/2009','mm/dd/yyyy') dt, 168 src, 'Y-L' the_name, 'HH' cod, 'AA' pad, ' BAN' tek FROM dual UNION all
SELECT 111 the_id, To_Date('11/3/2009','mm/dd/yyyy') dt, 168 src, 'G-H' the_name, 'BA' cod, 'WW' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('11/4/2009','mm/dd/yyyy') dt, 168 src, 'E-R' the_name, 'JJ' cod, 'XX' pad, ' DD' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('11/5/2009','mm/dd/yyyy') dt, 168 src, 'T-C' the_name, 'TT' cod, 'JJ' pad, ' WW' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('11/6/2009','mm/dd/yyyy') dt, 168 src, 'H-L' the_name, 'EE' cod, 'DD' pad, ' BAN' tek FROM dual UNION all
SELECT 111 the_id, To_Date('11/9/2009','mm/dd/yyyy') dt, 168 src, 'S-H' the_name, 'BA' cod, 'WW' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('11/10/2009','mm/dd/yyyy') dt, 168 src, 'H-R' the_name, 'VV' cod, 'FCY' pad, ' YY' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('11/30/2009','mm/dd/yyyy') dt, 90 src, 'V-C' the_name, 'GG' cod, 'FCS' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('12/1/2009','mm/dd/yyyy') dt, 90 src, 'B-L' the_name, 'QQ' cod, 'GG' pad, ' BAN' tek FROM dual UNION all
SELECT 111 the_id, To_Date('12/2/2009','mm/dd/yyyy') dt, 90 src, 'A-H' the_name, 'BA' cod, 'WW' pad, ' BAN' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('12/3/2009','mm/dd/yyyy') dt, 90 src, 'N-R' the_name, 'TT' cod, 'JJ' pad, ' TT' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('12/7/2009','mm/dd/yyyy') dt, 90 src, 'C-C' the_name, 'YY' cod, 'QQ' pad, ' WE' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('12/8/2009','mm/dd/yyyy') dt, 90 src, 'X-L' the_name, 'UU' cod, 'JJ' pad, ' BAN' tek FROM dual UNION all
SELECT 111 the_id, To_Date('12/9/2009','mm/dd/yyyy') dt, 90 src, 'V-H' the_name, 'BA' cod, 'PP' pad, ' YR' tek FROM dual UNION ALL
SELECT 111 the_id, To_Date('12/10/2009','mm/dd/yyyy') dt, 90 src, 'E-R' the_name, 'FIN2' cod, 'FCY' pad, ' RE' tek FROM dual UNION ALL
SELECT 112 the_id, To_Date('2/28/2009','mm/dd/yyyy') dt, 93 src, 'V-C' the_name, 'EE' cod, 'FCS' pad, ' BAN' tek FROM dual UNION ALL
SELECT 112 the_id, To_Date('3/2/2009','mm/dd/yyyy') dt, 93 src, 'A-S' the_name, 'BA' cod, 'WW' pad, ' TT' tek FROM dual UNION ALL
SELECT 112 the_id, To_Date('3/3/2009','mm/dd/yyyy') dt, 93 src, 'N-R' the_name, 'TT' cod, 'JJ' pad, ' TT' tek FROM dual UNION ALL
SELECT 112 the_id, To_Date('3/4/2009','mm/dd/yyyy') dt, 93 src, 'C-C' the_name, 'YY' cod, 'QQ' pad, ' WE' tek FROM dual UNION ALL
SELECT 112 the_id, To_Date('3/5/2009','mm/dd/yyyy') dt, 93 src, 'X-L' the_name, 'SS' cod, 'JJ' pad, ' BAN' tek FROM dual UNION all
SELECT 112 the_id, To_Date('3/6/2009','mm/dd/yyyy') dt, 93 src, 'V-H' the_name, 'BA' cod, 'PP' pad, ' YR' tek FROM dual UNION ALL
SELECT 112 the_id, To_Date('3/9/2009','mm/dd/yyyy') dt, 93 src, 'E-R' the_name, 'HH' cod, 'KK' pad, ' RE' tek FROM dual
)so as you can see, there are month end dates and well and daily dates. the daily are basically business days. what i want to do is the following
for a particular id, i would like to take the month end date, look forward 5 business day and copy the column values from the 5th business day
to the current row.
there is two exceptions:
1. i am only interested on those src=93 and 168.
2. the_name column will not be copy, but the rest will
so lets take an example, id = 111 src = 93. since i am only interested in src=93 and 168, this data fall in that category.
the month end dates for id=111 and src=93 are 6/30/09 and 7/31/2009.
in this case i want to look forward 5 business days. in the case of 6/30/09, the 5th business day is 10/7/2009 and for 7/31/2009 is 8/7/2009.
i want to take all the column values except the_name column and display those values for 6/30/09. same thing with 7/31/2009, take column values from 8/7/2009
and display those values.
so the output for 6/30/2009 should look like this
THE_ID DT SRC THE_NAME COD PAD TEK
111 6/30/2009 93 A-C DD BANif ou notice here 6/30/2009 retain the value for the_name column but took the values for the remaining column from 10/7/2009 (even the null values got copy)
the same logic should apply to 7/31/2009 and value should be taking from 8/7/2009
if the src is not equal to 93 or 168. then just display the data and no logic apply, for id=111 and src=90
no logic apply, the data should just be display.
i would like to write a query tha give me the output below.
i tried using last_value function but i am using oracle 9i and ignore null is not supported in oracle 9i. i need to copy null if the 5th day contain null in the columns
the final ouput for the data above should be this
THE_ID DT SRC THE_NAME COD PAD TEK
111 6/30/2009 93 A-C DD BAN
111 10/1/2009 93 B-L AA NN TT
111 10/2/2009 93 C-H BA RR BAN
111 10/5/2009 93 D-R HH FCY BANW
111 10/6/2009 93 E-C JJ EE JJ
111 10/7/2009 93 F-L DD FIC BAN
111 10/8/2009 93 G-H HG YY BAN
111 10/9/2009 93 K-R EE FCY BANW
111 7/31/2009 93 G-H EE FCY
111 8/3/2009 93 K-R EE FCY BANW
111 8/4/2009 93 K-R EE FCY BANW
111 8/5/2009 93 K-R EE FCY BANW
111 8/6/2009 93 K-R EE FCY BANW
111 8/7/2009 93 K-R EE FCY
111 6/30/2009 22 A-C AA BB CC
111 10/1/2009 22 B-L AA NN TT
111 10/2/2009 22 C-H BA RR BAN
111 10/5/2009 22 D-R HH FCY BANW
111 10/6/2009 22 E-C JJ EE JJ
111 10/7/2009 22 F-L DD FIC BAN
111 10/8/2009 22 G-H HG YY BAN
111 10/9/2009 22 K-R EE FCY BANW
111 10/30/2009 168 T-C EE DD BAN
111 11/2/2009 168 Y-L HH AA BAN
111 11/3/2009 168 G-H BA WW BAN
111 11/4/2009 168 E-R JJ XX DD
111 11/5/2009 168 T-C TT JJ WW
111 11/6/2009 168 H-L EE DD BAN
111 11/9/2009 168 S-H BA WW BAN
111 11/10/2009 168 H-R VV FCY YY
111 11/30/2009 90 V-C GG FCS BAN
111 12/1/2009 90 B-L QQ GG BAN
111 12/2/2009 90 A-H BA WW BAN
111 12/3/2009 90 N-R TT JJ TT
111 12/7/2009 90 C-C YY QQ WE
111 12/8/2009 90 X-L UU JJ BAN
111 12/9/2009 90 V-H BA PP YR
111 12/10/2009 90 E-R FIN2 FCY RE
112 2/28/2009 93 V-C BA PP YR
112 3/2/2009 93 A-S BA WW TT
112 3/3/2009 93 N-R TT JJ TT
112 3/4/2009 93 C-C YY QQ WE
112 3/5/2009 93 X-L SS JJ BAN
112 3/6/2009 93 V-H BA PP YR
112 3/9/2009 93 E-R HH KK REhi i am using oracle 9i 9.2.0.7.0
you are right about the 5th business day, for 6/30/2010 it should have been 8/7/2010. 7/31/2010 is a month end so it doesnt count when you go down the list of business days. and for 7/31/2010 the 5th business day should have been 10/7/2010.
sorry for the mistake, i got both of them backwards. so for the output, 6/30/2010 should copy from 8/7/2010 and 7/31/2010 from 10/7/2010
THE_ID DT SRC THE_NAME COD PAD TEK
111 6/30/2009 93 A-C EE FCY
111 8/3/2009 93 K-R EE FCY BANW
111 8/4/2009 93 K-R EE FCY BANW
111 8/5/2009 93 K-R EE FCY BANW
111 8/6/2009 93 K-R EE FCY BANW
111 8/7/2009 93 K-R EE FCY
111 7/31/2009 93 G-H DD BAN
111 10/1/2009 93 B-L AA NN TT
111 10/2/2009 93 C-H BA RR BAN
111 10/5/2009 93 D-R HH FCY BANW
111 10/6/2009 93 E-C JJ EE JJ
111 10/7/2009 93 F-L DD BAN
111 10/8/2009 93 G-H HG YY BAN
111 10/9/2009 93 K-R EE FCY BANWEdited by: elmasduro on May 10, 2010 11:53 AM
Maybe you are looking for
-
How do I access my "old Mail" account in my AOL mail folder?
When I access my AOL account from my Ipad, the folder for "old Mail" doesn't appear as a selection. How do I access this folder?
-
SES posting via worklfow is failing
Hi, Our SES acceptance workflow is failing to post an SES and returning error 'Field ESSR-BUDAT. is not an input field'. It uses a custom method from BO ZBUS2091, calling BDC in call transaction mode, calling txn ML81. The BDC returns the above messa
-
NEWS FROM TECH SUPPORT - UPDATED LINK COMING to SOLVE OUTLOOK SYNCING ETC
I talked to Tech support today Regarding Outlook sync... there is a work around... defining a hotmail account (with hotmail connector) in outlook , making hotmail the contact database.... it will sync to the online hotmail account . when you then cr
-
All, I'm in the process of re-building an AW using Non Aggregated Exports. All the importing into the new AW is completed. So I'm now in the process of maintain the base cubes, to aggregate the data. During the dialog via AWM, I'm given the option to
-
How to Hide Fields and shrink group in a crystal report
I am workling on a report that is looking for the top 15 accounts by state based on assets. I did that by creating a running total field and supressing anything where that running total field is greater than 15. However, my problem is that if the sta