Update table a columns using columns from table b (values of 2 columns of table b need to taken from table c)

Guys,
I need to update table A columns col3, col4, col5 and col6 by table b columns col3, col4, col5 and col6 however table b col5 and col6 values need to come from table c col1.
Means table b col5 and col6 have values in it however i need to replace them with value from table c col1 and need to update table a col5 and col6 accordingly.
table a and table b has col1 and col2 in common.
i am trying something like this.
Update a
a.col3 = b.col3,
a.col4 = b.col4,
a.col5 = (select col1 from table_c c where c.col2=b.col5),
a.col6 = (select col1 from table_c c where c.col2=b.col6)
from table_A a inner join table_b
on  a.col1=b.col1 and a.col2=b.col2
can someone help me reframe above update query?
thanks in advance for your help.

Try the below:(If you have multiple values, then you may need to use TOP 1 as commented code in the below script)
create Table tableA(Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int)
Insert into tableA values(1,2,3,4,5,6)
create Table tableB(Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int)
Insert into tableB values(1,2,30,40,50,60)
create Table tableC(Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int)
Insert into tableC values(100,50,30,40,2,2)
--Insert into tableC values(200,50,30,40,2,2)
Insert into tableC values(100,60,30,40,2,2)
Select * From tablea
Update a Set
a.col3 = b.col3,
a.col4 = b.col4,
a.col5 = (select col1 from tablec c where c.col2=b.col5 ),
a.col6 = (select col1 from tablec c where c.col2=b.col6 )
from tableA a inner join tableb b
on a.col1=b.col1 and a.col2=b.col2
--Update a Set
--a.col3 = b.col3,
--a.col4 = b.col4,
--a.col5 = (select Top 1 col1 from tablec c where c.col2=b.col5 Order by c.Col1 asc),
--a.col6 = (select Top 1 col1 from tablec c where c.col2=b.col6 Order by c.Col1 asc)
--from tableA a inner join tableb b
--on a.col1=b.col1 and a.col2=b.col2
Select * From tablea
Drop table tablea,Tableb,TableC

Similar Messages

  • [Forum FAQ] SharePoint 2013: Extracting values from a multi-value enabled lookup column and merge values to a multi-value enabled column

    For some business requirements, users want to extract values from a multi-value enabled lookup column
    and add items to another list based on each separate value. In contrast, others want to find duplicate values in the list and merge associated values to a multi-value enabled column and then
    add items to another list based on the merged value. All of these can be achieved using SharePoint Designer 2013 Workflow.
    How to extract values from a multi-value enabled lookup column and add items to another list based
    on each separate value using SharePoint Designer 2013.
    Important actions: Loop Shape; Utility Actions
    Three scenarios
    Things to note
    Steps to create Workflow
    How to merge values to a multi-value enabled column and add item to another list based on the
    merged value using SharePoint Designer 2013.
    Important actions: Call HTTP Web Service; Build Dictionary
    Things to note
    Steps to create Workflow
    How to
    extract values from a multi-value enabled lookup column and
    add items to another list based on each separate value using SharePoint Designer 2013.
    For example, they have three lists as below. They want to
    extract values from the Destinations column
    in Lookup2 and add items to Lookup3 based on each country and set Title to current item: ID.
    Lookup1:
    Title (Single line of text)
    Lookup2:
    Title (Single line of text), Destinations (Lookup; Get information from: Lookup1 in Title column).\
    Lookup3:
    Title (Single line of text), Country (Single line of text).
    Important action
    1. Loop Shape: SharePoint Designer 2013 support two types of loops: loop n times and loop with condition.
    Loops must also conform to the following rules:
    Loops must be within a stage, and stages cannot be within a loop.
    Steps may be within a loop.
    Loops may have only one entry and one exit point.
    2. Utility Actions: It contains many actions, such as ‘Extract Substring from Index of String’ and ‘Find substring in String’.
    Three scenarios
    We need to loop through the string returned from the look up column and look for commas. There are three
    scenarios:
    1.  No comma but string is non-empty so there is only one country.
    2.  At least one comma so there is at least two or more countries to loop.
    3.  In the loop we have consumed all the commas so we have found the last country. 
    Things to note
    There are two things to note:
    1. "Find string in string (output to Variable:index)"  will return -1 if doesn't find
    the searched for string.
    2. In the opening statement "Set Variable: Countries to Current Item:Destinations" set the return
    field as  "Lookup Values, Comma Delimited".
    Steps to create Workflow
    Create a custom list named Lookup1.
    Create a custom list named Lookup2, add column: Destinations (Lookup; Get information from: Lookup1 in Title column).
    Create a custom list named Lookup3, add column: Country (Single line of text).
    Create a workflow associated to Lookup2.
    Add conditions and actions:
    Start the workflow automatically when an item is created.
    Add item to Lookup2, then workflow will be started automatically and create multiple items to lookup3.
    See the below in workflow History List:
    How to merge values to a multi-value enabled column and add item to another list based on the
    merged value using SharePoint Designer 2013
    For example, they have three lists as below. They want to find duplicate values in the Title column in
    Lookup3 and merge country column to a multi-value enabled column and then add item to lookup2 and set the Title to Current Item: Title.
    Lookup1:
    Title (Single line of text)
    Lookup3:
    Title (Single line of text), Country (Single line of text).
    Lookup2:
    Title (Single line of text), Test (Single line of text).
    Important actions
    "Call HTTP Web Service"
    action: In SharePoint 2013 workflows, we can call a web service using a new action introduced in SharePoint 2013 named Call HTTP Web Service. This action
    is flexible and allows you to make simple calls to a web service easily, or, if needed, you can create more complex calls using HTTP verbs as well as allowing you to add HTTP headers.
    “Build Dictionary"
    action:
    The Dictionary variable type is a new variable type in the SharePoint 2013 Workflow.
    The following are the three actions specifically designed for the Dictionary variable type: Build Dictionary, Count Items in a Dictionary and Get an Item from a Dictionary.
    The "Call HTTP Web Service" workflow action would be useless without the new "Dictionary" workflow action.
    Things to note
    The
    HTTP URI is set to https://sitename/_api/web/lists/GetByTitle('listname')/items?$orderby=Id%20desc and the HTTP method is set to “GET”. Then the list will be sort by Id in descending order.
    Use Get
    d/results(0)/Id form
    Variable: ResponseContent (Output to
    Variable: maxid) to get the Max ID.
    Use Set
    Variable: minid to Current List:ID to get the Min ID.
    Use Copy from
    Variable: destianation , starting at
    1 (Output to
    Variable: destianation) to remove the space.
    Steps to create Workflow
    Create a custom list named Lookup1.
    Create a custom list named Lookup2, add column: Test (Single line of text).
    Create a custom list named Lookup3, add column: Country (Single line of text).
    Create a workflow associated to Lookup3.
    Add a new "Build Dictionary" action
    to define the http request header:
    Add a Call HTTP Web Serviceaction, click on
    this and paste your http request.
    To associate the
    RequestHeader variable, select the Call action property,
    set the
    RequestHeaders property to
    RequestHeader:
    In the Call action, click on
    response and associate the response to a new
    variable: ResponseContent (of type Dictionary).
    After the Call action add Get item from Dictionary action to get the Max ID.
    Add Set Workflow Variable action to get the Min ID.
    Add Loop Shape (Loop with Condition) to get all the duplicate titles and integrate them to a string.
    Create item in Lookup2.
    The final Stage should look like this:
    Start the workflow automatically when an item is created.
    Add item to Lookup3, then workflow will be started automatically and create item to lookup2.
    See the below in workflow History List:
    References
    SharePoint Designer 2013 - Extracting values from a multi-value enabled lookup column into a dictionary as separate items:
    http://social.technet.microsoft.com/Forums/en-US/97d34468-1b53-4741-88b0-958472f8ca9a/sharepoint-designer-2013-extracting-values-from-a-multivalue-enabled-lookup-column-into-a
    Workflow actions quick reference (SharePoint 2013 Workflow platform):
    http://msdn.microsoft.com/en-us/library/jj164026.aspx
    Understanding Dictionary actions in SharePoint Designer 2013:
    http://msdn.microsoft.com/en-us/library/office/jj554504.aspx
    Working with Web Services in SharePoint 2013 Workflows using SharePoint Designer 2013:
    http://msdn.microsoft.com/en-us/library/office/dn567558.aspx
    Calling the SharePoint 2013 Rest API from a SharePoint Designer Workflow:
    http://sergeluca.wordpress.com/2013/04/09/calling-the-sharepoint-2013-rest-api-from-a-sharepoint-designer-workflow/

    GREAT info, but it may be helpful to note that when replacing a portion of the variable "Countries" with a whitespace character, you may cause the workflow to fail in a few specific cases (certain lookup fields will not accept this and will automatically
    cancel).  I only found this out when recreating your workflow on a similar, but much more complex list set.  
    To resolve this issue, I used another utility action (Extract Substring from Index of List) to clear out the whitespace.  I configured it as "Copy from
    Variable: Countries, starting at
    1 (Output to Variable: Countries), which takes care of this issue in those few cases.
    Otherwise, WOW!  AWESOME JOB!  Thanks!  :)

  • Hello, I am trying to use a photo,that I've opened up in pages on a blank landscape, taken from my camera roll and use it as album cover art. All the custom text's will not paste when I copy.  Pic and texts are saved as a PDF, how can I paste the doc ?

    Hello, I am trying to use a photo,that I've opened up in pages on a blank landscape, taken from my camera roll and use it as album cover art. All the custom text's will not paste when I copy.  Pic and texts are saved as a PDF, how can I paste the doc ?

    Hello, I am trying to use a photo,that I've opened up in pages on a blank landscape, taken from my camera roll and use it as album cover art. All the custom text's will not paste when I copy.  Pic and texts are saved as a PDF, how can I paste the doc ?

  • TS1702 My IOS is 4.2.2 and my ipod doesnt accept later versions. Before updating the software, I used to have viber and now I can reinstall it, because it needs IOS 4.3 or later. Is there any place where I can get the older versions of this app?

    My IOS is 4.2.2 and my ipod doesnt accept later versions. Before updating the software, I used to have viber and now I can reinstall it, because it needs IOS 4.3 or later. Is there any place where I can get the older versions of this app? Also, there are others app that wont install, such as netflix, angry birds, etc
    Please, help me! I really need it!

    Only if you have it on your computer or in a computer file backup

  • How to handle the BOLB column Using JDBC adapter

    Hi,
      I want to sending of a BOLB column from a DB2 database table to another DB2 database, and the sender and receiver both by using JDBC adapter. The two tables in each other database have the same columns.
      Here is the table's structure:
      <ID>string type</ID>
      <PDF>blob type</PDF>
      Also, i haved create two DataTypes in PI system.
      Sender DataType:
      ns:DT_PDF_Req xmlns:ns="http://XXXXX.com/sap/xi">
       <row>
         <ID>1</ID>
         <PDF></PDF>
       </row>
      </ns:DT_PDF_Req>
      Receiver DataType:
      <ns0:DT_PDF_Res xmlns:ns0="http://XXXX.com/sap/xi">
      <STMT>
      <dbtable action="INSERT">
      <table>tablename</table>
      <access>
       <ID></ID>
       <PDF></PDF>
      </access>
      </dbtable>
      </STMT>
      </ns0:DT_PDF_Res>
    When test this interface, i found the that we can get the data, but when execute the insert stms  the follow errors occured  in RWB :
    <ERROR>
    Could not execute statement for table/stored proc. "DBDPUSER.pdf" (structure "STMT") due to com.ibm.db2.jcc.b.nm: DB2 SQL Error: SQLCODE=-103, SQLSTATE=42604, SQLERRMC=255044462d312e330a25c7ec8fa20a352030206f626a0a3c3c2f4c656e677468203620, DRIVER=3.50.153
    JDBC Message processing failed, due to Error processing request in sax parser: Error when executing statement for table/stored proc. 'DBDPUSER.pdf' (structure 'STMT'): com.ibm.db2.jcc.b.nm: DB2 SQL Error: SQLCODE=-103, SQLSTATE=42604, SQLERRMC=255044462d312e330a25c7ec8fa20a352030206f626a0a3c3c2f4c656e677468203620, DRIVER=3.50.153
    </ERROR>
    Can anybody tell me how to resolve the problems?
    And tell me about how to deal BOLB column using PI.
    Best Regards
    Terry

    Hi Terry Qin,
    I understand, you are getting below XML from sender JDBC channel. But when you getting SAX parser error, in receiver JDBC.
    <ns:DT_PDF_Req xmlns:ns="http://XXXXX.com/sap/xi">
    <row>
    <ID>1</ID>
    <PDF></PDF>
    </row>
    </ns:DT_PDF_Req>
    I think it is because the XML which is going to receiver JDBC channel is not well formed (because pdf can containg < & characters).
    You can achive this sceanrio, by selecting receiver JDBC channel as Message Protocol "Native SQL Format" [Link1|http://help.sap.com/saphelp_nwpi711/helpdata/en/44/7c24a75cf83672e10000000a114a6b/frameset.htm] you can send non XML to receiver channel.
    Before that, you have convert above input XML into SQL statement, using Java Mapping.
    Regards,
    Raghu_Vamsee

  • Update one column while getting the value in another column

    Is it possible to in one single SQL statement update two columns in a table while at the same time obtaining the value of another column, on the same row, in the same table, and independently (that is, the update of the columns has nothing to do with the data that I want from another column)*?* Of course, I can do this in two operations, one being a "select" and the other one being an "update", but since I am in the same table and even on the same row, is it really necessary to make TWO database calls? That's why I want to combine the the two SQL-statements, for reasons of presumed effiency.

    jsun wrote:
    Is it possible to in one single SQL statement update two columns in a table while at the same time obtaining the value of another column, on the same row, in the same table, and independently (that is, the update of the columns has nothing to do with the data that I want from another column)*?* Of course, I can do this in two operations, one being a "select" and the other one being an "update", but since I am in the same table and even on the same row, is it really necessary to make TWO database calls? That's why I want to combine the the two SQL-statements, for reasons of presumed effiency.Two statements != two database calls.
    At least not in terms of SQL.
    JDBC requires a 'statement' but in SQL (depending on the data source) that can include multiple statements. An obvious example of this is a stored proc but there are other ways as well.

  • IWork Numbers program. I am trying to create a 'Master Table'. The table will be used on numerous sheets, when cells altered on the 'Master' it will show on all sheets using the Master table. Is this a possibility??

    iWORK NUMBERS
    I am trying to create a 'Master Table'. This table will be used on numberous sheets, however not all. Items entered into the cells in the Master Table will then reflect in the used sheets that have the Master Table linked.
    On the individual pages however, they will be able to be altered purely for that page.
    Hope I have explained myself clearly,
    Would appreciate any help,
    Cheers,

    Hi Hilary,
    The formula in the Index column of the Main table is:
    E2: =IF(A,MAX($E$1:E1)+1,"")
    Fill down to the end of column E.
    The Breakout table contains a single formula:
    A2: =IF((ROW()-1)>MAX(Main :: $E),"",OFFSET(Main :: $A$1,MATCH(ROW()-1,Main :: $E,0)-1,COLUMN()))
    Fill down and right to fill the table.
    For multiple rooms (with different data transfered to each) you'll need a column of checkboxes and a corresponding index column for each room.
    The index columns can be hidden.
    Contents in individual cells in the breakout tabel(s) can be entered directly, replacing the formula. To retun to the calculated result, select a cell adjacent to the one where text was entered, and drag the Fill control handle (small circle, bottom right of the selection rectangle) to fill the formula back into that cell.
    Regards,
    Barry

  • Tabular form condition type value of item / column in expression 1

    Hi
    Question 1
    I was wondering if anyone can help with the necessary syntax so that I can set a Condition Type for a column in a Tabular Form.
    What I'm trying to do is show or hide a column based on the contents of another column in the same row for instance show column DETAIL or DETAIL_READ_ONLY if column READ_ONLY is set to 'Y'
    Value of item / column in expression 1 = #READ_ONLY# or READ_ONLY (alas neither works)
    Expression 2 = Y
    I can set all the DETAIL or DETAIL_READ_ONLY columns to either hide or show at the same time by
    Value of item / column in expression 1 = P100_READ_ONLY (works well but lacks granularity)
    Expression 2 = Y
    Question 2
    Are Tabular Forms such that all fuctionality has to be global, what effects one column must be the same for all
    I know that Oracle prefers that developers don't use tabular forms but they are usefull for data visability when setting up related data in the same table.
    e.g. surveys, questionnaires etc apps the web was made for
    Thanks
    Derek

    Hi Sandro
    Thanks for replying
    The problem I have is Tabular Forms
    Detail Text Detail Read Only Read only
    Event 1a Event 1b Y
    Event 2a Event 2b N
    Event 3a Event 3b Y
    What I want it to look like is
    Detail Text Detail Read Only Read only
    ___________Event 1b__________ Y
    Event 2a_____________________ N
    ___________Event 3b__________ Y
    This would mean that the Text Field containing Event 2 could be updated but the Display Only fields containing Event 1 and Event 3 cannot be changed.
    The trick is to be able to mix and match data types for the same data because Tabular Forms columns don't have a conditional read only choice.
    Sorry about the rudimentary diagram, but its the old 80 / 20 rule =>20 percent functional
    Edited by: derekf on 4/02/2013 17:50

  • Dynamic updates in dropdown field using presentation

    My requirement is as follows:
    1)     Combination of text box & dropdown in the presentation.
    2)     Dropdown is dependent on the text box.
    3)     If user will enter the two characters in the text box then automatically drop down will be fill the list of the string(s) starting with entered 2 characters.
    Ex:
    In side text box I entered “GO”.
    In the drop down it should populated with list of cities start with “GO”.
    Please let me know if any one having the solution satisfying above requirement.
    With Best Regards,
    Ratna Prasad,

    Hi,
    <div class="jive-quote"><span class="jive-quote-header">user11180317 wrote:
    I enter any text in the textbox and according to that i execute the query which is in the dynamic method of the referenced data of the drop down but nothing happens.So i called another method on change invoke having the refreshvalidvalues command then also nothing happened.</div>
    A few ideas when testing this.
    1. Double check your textbox that is supposed to update the attribute shown in the dropdown. Look at the textbox's Properties and verify that there is an "On change invoke" method associated with the field.
    2. Open the method referenced in the first step. The method should have the logic:
    logMessage "refreshing valid values" using severity = DEBUG
    refreshValidValues("theNameOfTheAttributeInTheDropdown")A common problem is when you leave the double quotes out of this logic (e.g. refreshValidValues(theNameOfTheAttributeInTheDropdown) will not work)
    3. Double check the attribute that you want to update dynamically. In the above step, the attribute's name is "theNameOfTheAttributeInTheDropdown". Open this attribute now and verify that in the Valid Values section for the attribute - there is a Dynamic method invoked that updates the permitted values for this attribute (and therefore the values shown in the dropdown).
    4. Open the method that updates the attribute's valid values dynamically (method found in step 3) and add a logMessage statement at the top like:
    logMessage "Entry - valid values update for attribute theNameOfTheAttributeInTheDropdown" using severity = DEBUGAfter the valid values have been retrieved, show this list using another logMessage statement in this method.
    5. Run the screenflow again from the WorkSpace and verify that dropdown is getting populated. If not - check the log file for the point of failure.
    Hope this helps,
    Dan

  • Need to reference a cell using a variable or cell value.

    Hi.
    I am trying to build a master sheet and then have sub sheets that detail the information from the master. My master sheet looks like this:
    1 | 101 | Bob | Smith |
    2 | 104 | Sally | Jones |
    3 | 108 | Tim | Abbott |
    Then on separate sheets I want a summary for each line like this:
    1 | Name | Bob |
    2 | ID | 101 |
    Now, I know I could just build this by creating references to the master sheet, but in reality my sheets are far more complex and I really need to be able to reference them by line number. So I would like to have a hidden cell (say AA1) on each summary which designates the line and then reference Master:B{AA1}. I did this years ago on excel but have no idea how I did it or howo to do it in Numbers.
    Any help is greatly appreciated.
    Thom

    Hi 86,
    Rearrange your table then add another table to find the result:
    A2 in Table 1-1 will find the earliest date in Table 1 without having to sort Table 1.
    A2 contains this formula
    =MIN(Table 1::A)
    B2 in Table 1-1 uses VLOOKUP to find which ID matches that MIN date.
    The reason for rearranging your table (Table 1) is that VLOOKUP compares a search value to the values in the leftmost column of a specified collection.
    (in this case, it looks in the leftmost column of the range Table1::A:B, then returns a match from column 2 of that range).
    I forgot to include "Exact Match" in the VLOOKUP formula. Is that what you want, or "Close Match"?
    Edit: I don't suppose that matters because MIN will always give an exact match. Duh!
    Regards,
    Ian.

  • Repost: Use Page-scope expressions in Value expressions

    Dear Adam Winer and expert group,
    I woud like to repost my problem. I had posted this in an earlier thread today. The issue that I would
    like to raise is regarding being able to use page-scoped beans in value expressions. I am trying to
    port some screens from Struts to JSF. Struts allows you to assign page-scoped beans to its input
    components. Adam Winer, you have been very helpful to me. I hope this issue can be solved.
    Thanks,
    Ajay
    Dear Adam Winer,
    I must admit that I am not able to understand your post properly. It is certainly because I have not
    properly understood the JSF architecture properly as yet.
    JSF automatically shows model bean values in the browser, and takes user input back into the model bean.
    But it would be nice to have the following scenario to work out....
    1. The JSP assigns the (initial) value to the JSF component.
    2. This value is displayed in the browser.
    3. When the user submits the form, the value goes to the model bean.
    Your post seems to indicate that the above is not possible. Could there not be any architectural
    workaround to make this possible ?
    Your post also seems to indicate that it is not possible to use an action from within a <c:forEach>.
    The following could also be perhaps ok (if it doesnt cause some other problem).
    <h:input_text initValue="#{pageScopeBean.someValue}" value="#{someBean.someValue}"><f:parameter initValue="#{status.count}" value="#{DataTable.selectedIndex}" />
    Perhaps, the expert team can come up with some brilliant solution. I am really keen.
    Ajay
    P.S ("Delayed execution", "Immediate execution", "does not exist on subsequent requests" are presently
    Greek and Latin to me.)
    No, that's not really possible, and it's not because
    we didn't try!
    "#{}" syntax means "evaluate this later". It has to
    mean that, for lots of reasons, including the need to
    evaluate these values on subsequent requests, and to
    evaluate these values repeatedly when a repeater
    component (like data_table) renders its output.
    Obviously, pageScope.status.count won't exist on
    subsequent requests, so that bit is hopeless. But it
    won't necessarily even work in the middle of the page,
    because there's no guarantee that the value of that
    <f:parameter> will only be used during the execution
    of <c:forEach>.
    We'd considered adding support for both delayed
    execution - "#{}" - and immediate execution - "${}" on
    JSF attributes, which would enable an example like
    this, but decided not to, for two reasons. First, it
    would be very confusing. Second, it actually opened a
    small security hole to do so that can't be solved
    without changes to the JSP EL architecture.
    -- Adam Winer (EG member)

    Dear Adam Winer,
    I read your post again and understood what you mean by "delayed execution" and "immediate execution".
    I am sorry, I think I read your post too quickly and hence didnt compherehend it.
    Please let me know if you think an alternative syntax such as
    <h:input_text initValue="#{pageScopeBean.someValue}" value="#{myBean.someValue}"/>Perhaps, this is not so different from the "#{}" and "${}" syntax that was discussed in the expert group.
    I am trying to imagine why a security loop-hole could be caused. If Struts doesnt have any problem
    getting values from a page-scoped bean, why does JSF have the problem ?
    Thanks for your help.
    Ajay
    We'd considered adding support for both delayed
    execution - "#{}" - and immediate execution - "${}" on
    JSF attributes, which would enable an example like
    this, but decided not to, for two reasons. First, it
    would be very confusing. Second, it actually opened a
    small security hole to do so that can't be solved
    without changes to the JSP EL architecture.

  • I have had money taken from my sype credit and I ...

    I am at Southampton Airport and was asked if I wanted to join Bingo Hotspot using my skype account. When I agreed to this I had £3.50+ taken from my skype credit. Why?? There was no notification that this would happen.
    Please can you find out why this has happened and get me a refund to my account.
    Thanks
    Simon

    You were using "Skype WiFi" - More information here: http://www.skype.com/en/features/skype-wifi/
    You should've seen this notification window which names the minutely price for the WiFi access:
    Were you using the latest version of Skype for Mac? You can check your version number in the menu "Skype -> About".
    Were you using Skype in English interface language?
    Follow the latest Skype Community News
    ↓ Did my reply answer your question? Accept it as a solution to help others, Thanks. ↓

  • HT1766 Is there any way to restore from an older backup? I need the one from about an hour ago!

    Is there any way to restore from an older backup on an iPhone 4S? I need the one from about an hour ago!

    If you have Time Machine and it ran after the backup you want and before the current backup you can restore it from the Time Machine backup.

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • How to update the COST column using another table's column

    Dear All,
    I have table:
    table parts: pno, pname, qoh, price, olevel
    table orders: ono, cno, eno, received, shipped
    table odetails: ono, pno, qty
    view:orders_view: ono, cno, eno, received, shipped,sum(qty*price)order_costview:odetails_view: ono, pno, qty, (qty*price)cost
    after I update the price in parts, I need to update COST and ORDER_COST too. The orders_view does not have pno, qty, and price, the odetails_view does not have price, how can I update the COST and ORDER_COST. Please help and Thanks in advance!!!
    I wrote the update the price in parts:
    create or replace procedure change_price(ppno in parts.pno%type, pprice in parts.price%type) as
    begin
        update parts
        set price = pprice
        where pno = ppno;
    end;
    show errorsthis procedure works fine.
    I wrote the trigger:
    create or replace trigger update_orders_v
    after update of price on parts
    for each row
    begin
        update orders_view
        set order_cost = sum(parts.(:new.price)*parts.qty)
        where parts.pno = :new.pno;
    end;
    show errorsIt gives me:Errors for TRIGGER UPDATE_ORDERS_V:
    LINE/COL ERROR
    3/5 PL/SQL SQL Statement ignored
    4/22 PL/SQL ORA-00934: group function is not allowed hereplease help!

    You could add the columns to the tables and then you would need a trigger to update those columns. However, you could just as easily select the price * qty to get the cost, without creating an additional column or trigger. I have no idea what you might want to do with a global temporary table. I think you need to explain what your purpose is, before any of us can suggest the best method. Since I have already demonstrated an update with a view, I will demonstrate an update with the cost column added to the odetails table and a trigger as you asked about. Notice that you will need triggers on both tables, the one that has qty and the one that has price.
    scott@ORA92> create table parts
      2    (pno    number(5) not null primary key,
      3       pname  varchar2(30),
      4       qoh    integer check(qoh >= 0),
      5       price  number(6,2) check(price >= 0.0),
      6       olevel integer)
      7  /
    Table created.
    scott@ORA92> create table odetails
      2    (ono    number(5),
      3       pno    number(5) references parts,
      4       qty    integer check(qty > 0),
      5       cost   number,
      6       primary key (ono,pno))
      7  /
    Table created.
    scott@ORA92> create or replace procedure change_price
      2    (ppno   in parts.pno%type,
      3       pprice in parts.price%type)
      4  as
      5  begin
      6    update parts
      7    set    price = pprice
      8    where  pno = ppno;
      9  end;
    10  /
    Procedure created.
    scott@ORA92> create or replace trigger update_cost1
      2    after insert or update of price on parts
      3    for each row
      4  begin
      5    update odetails
      6    set    cost = qty * :new.price
      7    where  pno = :new.pno;
      8  end update_cost1;
      9  /
    Trigger created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> create or replace trigger update_cost2
      2    before insert or update of qty on odetails
      3    for each row
      4  declare
      5    v_price parts.price%type;
      6  begin
      7    select price
      8    into   v_price
      9    from   parts
    10    where  pno = :new.pno;
    11    --
    12    :new.cost := :new.qty * v_price;
    13  end update_cost2;
    14  /
    Trigger created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> insert into parts values (1, 'name1', 1, 10, 1)
      2  /
    1 row created.
    scott@ORA92> insert into odetails values (1, 1, 22, null)
      2  /
    1 row created.
    scott@ORA92> -- starting data:
    scott@ORA92> select * from parts
      2  /
           PNO PNAME                                 QOH      PRICE     OLEVEL
             1 name1                                   1         10          1
    scott@ORA92> select * from odetails
      2  /
           ONO        PNO        QTY       COST
             1          1         22        220
    scott@ORA92> -- update:
    scott@ORA92> execute change_price (1, 11)
    PL/SQL procedure successfully completed.
    scott@ORA92> -- results:
    scott@ORA92> select * from parts
      2  /
           PNO PNAME                                 QOH      PRICE     OLEVEL
             1 name1                                   1         11          1
    scott@ORA92> select * from odetails
      2  /
           ONO        PNO        QTY       COST
             1          1         22        242
    scott@ORA92> -- select works without extra cost column or trigger:
    scott@ORA92> select o.ono, o.pno, o.qty, (o.qty * p.price) as cost
      2  from   odetails o, parts p
      3  where  o.pno = p.pno
      4  /
           ONO        PNO        QTY       COST
             1          1         22        242
    scott@ORA92>

Maybe you are looking for