Update a field based on a max select query
Hi
I am just learning SQL so apologies if this is simple to you guys.
I have a table called [Stock WIP Table] which has duplicates in it. I have an [autonumber] field, a [palletid] field, and a [number5] field. I have the select query working to show the most recent record for each palletID:
SELECT
PalletID,MAX(autonumber)
FROMdbo.[Stock
WIP Table]
GROUPBYPalletID
How do I get the query to now delete all rows that are not in the select query?
Alternatively how could I add update the [number5] field to '1' where the [autonumber] is in the select and I can then delete all records that do not contain a '1' in [number5]
Can anyone help?
Thanks
AJ
Hi
I am just learning SQL so apologies if this is simple to you guys.
I have a table called [Stock WIP Table] which has duplicates in it. I have an [autonumber] field, a [palletid] field, and a [number5] field. I have the select query working to show the most recent record for each palletID:
SELECT
PalletID,MAX(autonumber)
FROMdbo.[Stock
WIP Table]
GROUPBYPalletID
How do I get the query to now delete all rows that are not in the select query?
Alternatively how could I add update the [number5] field to '1' where the [autonumber] is in the select and I can then delete all records that do not contain a '1' in [number5]
Can anyone help?
Thanks
AJ
Simply this for the DELETE
DELETE t
FROM dbo.[Stock WIP Table]t
WHERE EXISTS (SELECT 1
FROM dbo.[Stock WIP Table]
WHERE PalletID = t.PalletID
AND autonumber > t.autonumber)
No need of UPDATE bit value and then deleting. just above will ensure it gets deleted in single step
another method you may use is this
DELETE t
FROM dbo.[Stock WIP Table] t
CROSS APPLY (SELECT MAX(autonumber) AS MaxID
FROM dbo.[Stock WIP Table]
WHERE PalletID = t.PalletID
)t1
WHERE t1.MaxID <> t.autonumber
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Similar Messages
-
Populate text field based on the lov selected value
Hi,
based on the value selected in lov, i want to populate another text field. Below is the code I have written
In PFR:
if(pageContext.isLovEvent())
String lovInputSourceId = pageContext.getParameter(SOURCE_PARAM);
if ("lovCategory".equals(lovInputSourceId))
java.util.Hashtable lovResults = pageContext.getLovResultsFromSession(lovInputSourceId);
if(lovResults!=null)
String value =(String)lovResults.get("lovCategory");
amobj.categorycode(value);
AMImpl code:
public void categorycode(String code) {
sundryCodeVOImpl vobj = getsundryCodeVO1();
vobj.setWhereClause( "lookup_code = "+"'"+code+"'");
vobj.reset();
vobj.executeQuery();
String desc = vobj.first().getAttribute("Description").toString();
String attr = vobj.first().getAttribute("Attribute1").toString();
testEOViewImpl vobj1 = gettestEOView1();
vobj1.getCurrentRow().setAttribute("CodeDescription",desc);
vobj1.getCurrentRow().setAttribute("PurchasingCategoryCd",attr);
vobj1.executeQuery();
With this code, the updated values for the attributes CodeDescription, PurchasingCategoryCd are getting inserted into the database table but they are now showing up in the text fields when a value is selected in lov.
Please tell me what is the mistake I'm doing.
Thanks
SunnyI'm using Lov Map to populate the lov field say field A. But I need to populate another field say field B based on the value selected in field A.
to give an example of my requirement. Consider a view object having attributes col1,col2,col3 and having following data.
col1--col2--col3
1-----a-------x
2-----b------y
3-----c------z
I 'll populate the lov of field A with values in col1. when user selects value 1 in field A. automatically field B should show value 'a'. If user selects value 2 in field A, field B should show value 'b' so on.
Thanks
Sunny -
Need to change the LOV field based on checked box selection in OAF page
Dear ALL,
I have a requirement as below:
I have a custom OAF page having a lov field which is mandatory, a check box and a two text fields.
So based on LOV value selection i am defaulting two text field value automatically.
So my requirement is when user selects the check box automatically the LOV field should be non mandatory and user can insert in values to the lov field and text field and submit it.
SO basically based on check box field selection i need to make the lov field in such a way it should accept all the values what user enters instead of check the query added in VO behind the LOV.
Please suggest me some pointers to achieve this requirement.
Thanks
Debhi,
in PFR use:
if ("checkevent".equals(pageContext.getParameter(EVENT_PARAM)))
HashMap hashMap = new HashMap();
String checkboxval=pageContext.getParameter("item2");
hashMap.put("checkboxval",checkboxval);
pageContext.setForwardURLToCurrentPage(hashMap ,
true, // retain the AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
OAWebBeanConstants.IGNORE_MESSAGES);
and in PR use:
if((pageContext.getParameter("checkboxval'))!=null)
OAMessageLovInputBean lovInputBean=(OAMessageLovInputBean)webBean.findIndexedChildRecursive("item3");
lovInputBean.setRequired("false");
try it
Regards
Mahesh -
How to create a form that can auto-populate all fields based on a specific selection?
We have created a template for each type of package used in our business. The template is the same but depending on the package selected, the fields would be populated differently. How can we create a template to load the fields based on the specific package selected? We use Adobe Acrobat Pro in creating the templates.
This forum is for the Adobe FormsCentral (http://formscentral.adobe.com) which is a service that allows you to create, collect and analyze data using an online web form. You should ask Acrobat/PDF related form questions in the Acrobat forums:http://forums.adobe.com/community/acrobat/acrobat_windows
I'll move your post to that forum so you don't need to retype it. They can help you out...
Randy -
Informatica updates not coming through to DAC for Select Query Ora-01007
I updatee a BI App Workstream to include a few fields, Request Dimension mapplet to be specific.
Informatica changes go just fine and I updated the query used as the select to do my inserts. When I run the task through DAC, I see all my changes except for the user query and it is causing me an 'ORA-01007: variable not in select list' Error because my Select does not match the Bulk insert number of items.
Can anyone suggest where I can look to force my modified query to run as part of the task and not the Original Old User Select query?
Thanks for the help.
RichI updatee a BI App Workstream to include a few fields, Request Dimension mapplet to be specific.
Informatica changes go just fine and I updated the query used as the select to do my inserts. When I run the task through DAC, I see all my changes except for the user query and it is causing me an 'ORA-01007: variable not in select list' Error because my Select does not match the Bulk insert number of items.
Can anyone suggest where I can look to force my modified query to run as part of the task and not the Original Old User Select query?
Thanks for the help.
Rich -
Select or update a field based on a column on another row
hi
I have some 5000 rows for the following combination of columns. Each combination has two rows. The only difference between these two rows is an indicator field. If one row for the same combination is having indicator as 'M' the other row for the same combination should ideally have indicator 'R'. But unfortunately the other row's indicator is null.
ie. if the first row for same combination of fields, indicator is 'M. then other one is null which should have been 'R'. If the first row is 'R' then other one is again null which should have been 'M'.
PRODUCT_NO STATE MONTH INDICATOR
1001 CA SEPT M
1001 CA SEPT null
1002 NY OCT R
1002 NY OCT null
Here for the first combination indicator is M and other one is null. But i need to update it to 'R' since other rows is M.
Same way for second combination first row is R second row then should have M as indicator.
Basically it is changing field to a value based on the value in the other rows indicator for the same combination of the above columns.
Please help if anybody has idea to do this in simple steps
ThanksIs this what you are looking for?
WITH TABLE_A AS
SELECT '1001' PRODUCT_NO, 'CA' STATE, 'SEPT' MONTH, 'M' INDICATOR FROM DUAL UNION ALL
SELECT '1001' PRODUCT_NO, 'CA' STATE, 'SEPT' MONTH, null INDICATOR FROM DUAL UNION ALL
SELECT '1002' PRODUCT_NO, 'NY' STATE, 'OCT' MONTH, 'R' INDICATOR FROM DUAL UNION ALL
SELECT '1002' PRODUCT_NO, 'NY' STATE, 'OCT' MONTH, NULL INDICATOR FROM DUAL UNION ALL
SELECT '1003' PRODUCT_NO, 'LA' STATE, 'NOV' MONTH, 'R' INDICATOR FROM DUAL UNION ALL
SELECT '1003' PRODUCT_NO, 'LA' STATE, 'NOV' MONTH, 'M' INDICATOR FROM DUAL
SELECT
PRODUCT_NO,
STATE,
MONTH,
DECODE(A.INDICATOR,NULL,(SELECT DECODE(B.INDICATOR,'R','M','R') FROM TABLE_A B WHERE B.PRODUCT_NO = A.PRODUCT_NO AND B.STATE = A.STATE AND B.MONTH = A.MONTH AND B.INDICATOR IS NOT NULL), A.INDICATOR) INDICATOR
FROM
TABLE_A A -
Having a problem using Workflow to update a field based on ZIP code
I created a Workflow to update a Yes/No picklist called eligibility based on a Text (Short) field called Applicant ZIP code.
It's set to update on the Opportunity page:
Before modified record saved
And the value function is:
IIf(InStr("60601_60602",[<stApplicant_Zip_Code_ITAG>|http://forums.oracle.com/forums/]+)>0,"Yes","No")+
That was a guess of how to try it while relying on my limited MS SQL & Access knowledge.
It does work correctly using what I did. The problem I have is that I actually need to choose from over 600 ZIP codes. The function window only allows for 256 characters. (And I suspect my way is fairly inelegant for search a multi-thousand character string.)
Any suggestions?I created a Workflow to update a Yes/No picklist called eligibility based on a Text (Short) field called Applicant ZIP code.
It's set to update on the Opportunity page:
Before modified record saved
And the value function is:
IIf(InStr("60601_60602",[<stApplicant_Zip_Code_ITAG>|http://forums.oracle.com/forums/]+)>0,"Yes","No")+
That was a guess of how to try it while relying on my limited MS SQL & Access knowledge.
It does work correctly using what I did. The problem I have is that I actually need to choose from over 600 ZIP codes. The function window only allows for 256 characters. (And I suspect my way is fairly inelegant for search a multi-thousand character string.)
Any suggestions? -
Need to display fields based on first filed selection
Hi All
I am useing Apex 4.1 on 11gr2
I am building an application that needs to have some fields completed based on the selection of the first file that is a LOV pick list.
I am using the display condition for the edit of existing records, but now need to be able to create a new record.
I thought I would have the screen redraw but that also resets the first field.
Any help would be great.
Edited by: merph on Oct 12, 2011 3:28 PM
Sorry guys I found the answer,, getting to like apex ;-)
Edited by: merph on Oct 12, 2011 3:57 PMSilly me it's right there
-
Can we return a value in two field based on a value select in LOV?
Hello expert.
i have a lov attached to a non-bind text field. when i select a value from non bind field lov, a record group of another LOV attached to a database item field generated. both text field are in same block.
LOV record group query of non-bind field is:
select cli_desc,cli from ivt_cli_mst
mapping is done for same lov field.
as: LOV record group query of database item_field :blk_stg_mst.item_cd is
select a.item_cd,b.short_desc
from storg_mst a,item_mst b
where a.item_cd = b.item_cd
and substr(a.item_cd,3,2) = :blk_stg_mst.nb_cli_cd(non bind LOV attached field)
and a.store_cd= :blk_store_mst.store_cd
order by item_cd
requirement:
i want as i select a value from LOV in non_bind field , value display in non_bind field as well as database item_field:
i.e in :blk_stg_mst.item_cd also.
please help.
thanks yashhi,
assign LOV to database item.(as usual setting the lov reuturn column to it). in the when validate item of database field assign value to no db field(something like if :db column is not null then :nondb_col := :dbcolumn). -
Automatically update text field depending on the in select list value
I have got 2 tables. Table A (Employee Personal Detail), Table B (Employee Academic detail). Employee no is common field between two tables).
I have created interactive report with form on table b using in-built templates. I have added text box on form to display employee name which is stored in table A. I want to automatically display employee name depending upon value in employee no field on form. I know I can write query to get value in employee name field. It gives me error when employee no is blank. How to handle error?Sagar,
For the employee name value to change according to the emp_no, your page needs to get submitted. can you use a select list with submit for emp_no? And then use the PL/SQL mentioned above to run on page submit?
I'm not sure but I guess you can also achieve this in Ajax. May be someone expert in that could help. -
WriteBack: Update a field based on two conditions.
Hi Experts,
I am facing a serious problem in write back to database.
Let me explain the writeback i am trying to do.
I have a table as Below
Col1----- Col2---------Col3----------Col4
100--------1-------------2----------100/(1+2)
Col1,col2,col3 are editable.
Once the values are entered in these columns Col4 is calculated by the formula (Col1/(Col2+Co3))
If the user enters 0 in col2 and col3 then it will be a division by zero which i have handled by the DECODE function
But the user requires a standard value to be shown there that is Col1/0.57895 whenever he enters 0 in col2 and col3.
I initiially put a column formula for Col4 in answers saying if col2 or col3 = 0 then (Col1/0.57895)
But as this formula is only at the prsentation level...teh values were not getting saved in the database.
My requirement is i need to put this condition in the writeback xml itself and see to it that this standard value be updated in the table itself.
like
update table set col4=Col1/0.57895 where col2=0 and col3=0
Update table set col4=(Col1/(Col2+Co3)) where col2 <>0 or col3<>0
I am unable to use two update queries in teh xml template.
Please let me know how can i implement this in the xml template.
Appreciate your immediate response.
-Best Regards!You can't do it in the xml but you can do it in the database with a before trigger update
http://www.techonthenet.com/oracle/triggers/before_update.php -
Hi all,
LOOP AT ITAB.
IF S_KUNNR IS not INITIAL.
SELECT MAX( MBLNR ) FROM MSEG INTO MBLNR
WHERE MATNR EQ ITAB-MATNR
AND KUNNR EQ ITAB-KUNNR
AND BWART eq '951'.
else.
SELECT MAX( MBLNR ) FROM MSEG INTO MBLNR
WHERE MATNR EQ ITAB-MATNR
AND KUNNR ne ' '
and sobkz eq 'V'
AND BWART eq '951'.
endif.
i need mjahr also from mseg .Top part is working.
LOOP AT ITAB.
IF S_KUNNR IS not INITIAL.
SELECT MAX( MBLNR ) mjahr FROM MSEG INTO MBLNR mjahr
WHERE MATNR EQ ITAB-MATNR
AND KUNNR EQ ITAB-KUNNR
AND BWART eq '951'.
else.
SELECT MAX( MBLNR ) mjahr FROM MSEG INTO MBLNR mjahr
WHERE MATNR EQ ITAB-MATNR
AND KUNNR ne ' '
and sobkz eq 'V'
AND BWART eq '951'.
endif.
after adding mjahr its not working.how to write query for that.Like this:
tables: mseg.
data: mblnr like mseg-mblnr,
mjahr like mseg-mjahr.
parameter: p_matnr like mseg-matnr.
SELECT MAX( MBLNR ) mseg~mjahr FROM MSEG INTO (MBLNR, mjahr)
where matnr eq p_matnr
GROUP BY mseg~mjahr.
WRITE:/ MBLNR, MJAHR.
ENDSELECT.
Pl. see ur other thread on the same and close either of them.
thanks\
Mahesh -
How to display F4 values in one field based on other field selection
Hi All,
How to hide a UI element (i.e Link to action) highlited for Normal User and display the same to super user.
Component Name : /SAPSRM/WDC_DODC_SC_GAF_C
2.Can i know how to display the entries in supplier field based on Product category selection.
Right now all the entries are getting displayed in the supplier field.
I want to display only entries based on Product category.
Search Help Name : BBP_BUPA_CLL_PARTNER
Component Name : /SAPSRM/WDC_DODC_SC_I_LIM
How to enhance the web dynpro component with the filtered values.
Regards,
Krish.Hi Ashvin,
Thanks for the document. In the search help there is a standard FM which is getting executed.
Can i enhance that FM or should i copy and edit.
BBP_F4IF_SHLP_EXIT_CLL_PARTNER
If i creata a Z FM and make changes how to pass that values to my standard Component View UI Element.
If not then suggest me some alternative.
Regards,
Krish -
Showing/Hiding certain fields based on Radioset selection
Hello all,
I'm like to know whether it is possible to Show/Hide certain fields using a RadioSet selection as it is done in Forms in ADF UIX. Kindly go through this post.
Showing/Hiding certain fields based on Radio Group selection
kindly help me out on this.
Thanks & Regards,
Arun.VHi Arun,
Here is what I do with my checkboxes, but I think that the radiobutton will do the same:
<af:selectBooleanCheckbox text="selectBooleanCheckbox 1"
label="Label 1"
binding="#{backing_page1.selectBooleanCheckbox1}"
id="selectBooleanCheckbox1"
autoSubmit="true"
immediate="true"/>
<af:inputText label="Label 1" binding="#{backing_page1.inputText1}"
id="inputText1"
disabled="#{!backing_page1.selectBooleanCheckbox1.selected}"
partialTriggers="selectBooleanCheckbox1"
value="#{backing_page1.selectBooleanCheckbox1.selected}"/> -
Plot a chart dynamically based on the values selected
Hi All,
I have some requirement like this i want to plot a chart . The chart should change dynamically based on target_name and date. What type of UI should I use ? I tried using multiselect or shuttle for choosing the target_name and date picker tool for date once i choose all this the chart should appear. Can I have a custom button called submit so once all the values are entered it plots chart ? Please help me out with our ideas.
Thanks in AdvanceHi,
Using the dependent value sets you can govern the values which can be selected based on a specific value selected in a particular segment. Example if Country name is selected in segment 1 then specific states names as per the country selected can be displayed in segment 2.
As per the requirement described you want to enable different fields based on the value selected in segment1, currently there is no standard mechanism available to enable/disable fields based on a value and you will have to do an extension/customization to meet this requirement.
Thanks,
Sanjay
Maybe you are looking for
-
How can I close nested folders in mail
I use folders in Outlook. LOTS of folders. They Re carefully arranged and nested for easy navigation. When I open Mail on the iPad I see ALL of my folders by default. There does not seem to be an option to collapse the view. This makes the Mail progr
-
iphone 4 not recognized and will not sync after latest itunes update. I have done recommendedl trouble shooting and uninstalled and reinstalled itunes to no avail. Can I go back to earlier version of itunes or restore computer to fix?
-
Need iMac G5 (iSight) monitor calibration help (RGB Channels?)
I understand the need to calibrate my display so that the final print matches what I see on my display. I plan to use the Gretag Macbeth Eye One Display calibrator, which I have already used on my last CRT monitor, with good results. I needed to adju
-
How to configure one time customer
Dear Friends, Please guide me how to configure one time custoemer in 6.0 version. Regards, Sreehari Message was edited by: Sreehari Kondapalli Message was edited by: Sreehari Kondapalli
-
BI-Content Install Help Required Please....I am Stumped
I've just installed NW 2004 SP1, successfully with ABAP+JAVA on one machine. Am presently applying support package stack 14. When I try to install the BI 3.53 Content add on I am having problems...:( The system does not seem to have BI-Cont installed