Dynamic Update Query

HI All,
Please find below DML script.
CREATE TABLE UP_A(ID INT , VAL VARCHAR(50))
GO
INSERT INTO UP_A VALUES(100,'Hundred')
INSERT INTO UP_A VALUES(1001,'Hundred and one')
INSERT INTO UP_A VALUES(1000,'Thousand')
INSERT INTO UP_A VALUES(1005,'Thousand and five')
go
CREATE TABLE UP_B(ID1 INT,ID2 INT,VAL1 VARCHAR(50),VAL2 VARCHAR(50))
GO
INSERT INTO UP_B(ID1,ID2) VALUES(100,1000)
INSERT INTO UP_B(ID1,ID2) VALUES(1001,1005)
GO
SELECT * FROM UP_A
SELECT * FROM UP_B
i wants to update Table UP_B Val1 and Val2 columns Based on Table UP_A ID Values.
Example : in Table UP_A for ID=100 the VAL='Hundred' So, this has to be updated in Table UP_B Val1 column. In the same way i wants to update all respective Val1 and Val2 from the respective Val from Table UP_A. 
Is there way to update with single UPDATE Query.
Thanks in advance.
bala krishna

Thank you for tryign, but you got it wrong. You ha be no idea what a tahel is, how to naem data element or SQL syntax:
CREATE TABLE UP_A
(ID INT , VAL VARCHAR(50))
GO
INSERT INTO UP_A VALUES(100,'Hundred')
INSERT INTO UP_A VALUES(1001,'Hundred and one')
INSERT INTO UP_A VALUES(1000,'Thousand')
INSERT INTO UP_A VALUES(1005,'Thousand and five')
go
CREATE TABLE UP_B(ID1 INT,ID2 INT,VAL1 VARCHAR(50),VAL2 VARCHAR(50))
GO
INSERT INTO UP_B(ID1,ID2) VALUES(100,1000)
INSERT INTO UP_B(ID1,ID2) VALUES(1001,1005)
GO
SELECT * FROM UP_A
SELECT * FROM UP_B
i wants to update Table UP_B Val1 and Val2 columns Based on Table UP_A ID 
Thank you for trying to post DDL,  but you got it wrong. You have no idea what a table is, how to name data element or SQL syntax. 
CREATE TABLE Numeric_Somethings
(numeric_value INTEGER NOT NULL PRIMARY KEY, 
 display_txt VARCHAR(20) NOT NULL);
INSERT INTO Numeric_Somethings
 VALUES(100, 'Hundred'), 
     (1001, 'Hundred and one'), 
     (1000, 'Thousand'), 
     (1005, 'Thousand and five');
A table is not a file. Try this design:
CREATE TABLE Redundant_Somethings
(numeric_value_1 INTEGER NOT NULL
  REFERENCES Numeric_Somethings(numeric_value),
 numeric_value_2 INTEGER NOT NULL
  REFERENCES Numeric_Somethings(numeric_value),
PRIMARY KEY (numeric_value_1, numeric_value_2)); -- guess! 
INSERT INTO Redundant_Somethings(numeric_value1, numeric_value2) VALUES(100, 1000), (1001, 1005)
>> I wants to update Table Redundant_Somethings ..<<
You might, but an SQL Programmer will use a VIEW that is always correct
CREATE VIEW Double_Stuff
AS 
SELECT R.numeric_value_1, R.numeric_value_2
       N1.display_txt, N2.display_txt
  FROM Redundant_Somethings AS R,
       Numeric_Somethings AS N1, Numeric_Somethings AS N2
 WHERE R.numeric_value_1 = N1.numeric_value
   AND R.numeric_value_2 = N2.numeric_value;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • How to generate a dynamic update query to update error flag in a mapping?

    i have a mapping in which i m loading log table through generated parameter file.But i want to update the error flag using dynamic update query.for that i have to generate a query and use update sqloverridw in target instances.but i m not getting how to implement it.Please help..!!

    Hi  All, I have a scenario. Below is the source record. field1|field2|field3|field4|field5|field6|field7
    5|20150329|1|980100001|500|My name is Lalita|25
    5|20150329|1|303444442|200|My name is |Lalita.I work in TCS|26
    5|20150329|1|442101001|1000|My name is Lalita.I worked Syntel|56
    5|20150329|1|446788900|300|My name|67  My source file is | separator. But for field6 the data might come with '|'.
    So I want to import the data along with '|' after separating all field in Informatica Layer.  Source team is not going to preformat the file. Please suggest how to achive this.

  • How to dynamically update columns in a where clause to a SQL query in OSB?

    Hi Gurus,
    I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
    For example:
    If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
    We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
    I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
    Thanks in advance
    Surya

    I solved my problem.
    In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
    Thank you to who took some time to think about it.
    Marc

  • If statement in update query

    I was wondering if you could have a cfif statement inside of a update query.  See example below.  Is there a better way of doing it? thanks.
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = #URL.var0#
                <cfif IsDefined("URLvar13">
                ,Q1_answer = #URL.var13#
                </cfif>
            WHERE ID = #session.member_id#
      </cfquery>

    TheScarecrow,
    Yes, dynamic query statements can be assembled using <cfif>.  I would suggest you switch your IsDefined() to a StructKeyExists() and strongly suggest you make good use of <cfqueryparam>:
    <cfquery DATASOURCE="xxx" name="update">
      UPDATE plant_gen_info
            SET levels_complete = <cfqueryparam value="#URL.var0#" cfsqltype="****">
                <cfif StructKeyExists(URL, "var13")>
                ,Q1_answer = <cfqueryparam value="#URL.var13#" cfsqltype="****">
                </cfif>
            WHERE ID = <cfqueryparam value="#session.member_id#" cfsqltype="****">
      </cfquery>
    I put a "****" placeholder for cfsqltype attributes because I'm not sure which would be appropriate for your variables.  See the help docs for more on the cfqueryparam and cfsqltype.
    -Carl V.

  • Setting Column Names in Dynamic Pivot Query

    Hi all,
    I'm having trouble setting column names in a dynamic pivot query and was wondering if someone could please help me figure out what I need to do.
    To help you help me, I've setup an example scenario in my hosted account. Here's the login info for my hosted site at [http://apex.oracle.com]
    Workspace: MYHOSTACCT
    Username : DEVUSER1
    Password : MYDEVACCTAnd, here is my test application info:
    ID     : 42804
    Name   : dynamic query test
    Page   : 1
    Table 1: PROJECT_LIST         (Alias = PL...  Listing of Projects)
    Table 2: FISCAL_YEAR          (Alias = FY...  Lookup table for Fiscal Years)
    Table 3: PROJECT_FY           (Alias = PF...  Intersection table containing project fiscal years)
    Table 4: PROJECT_FY_HEADCOUNT (Alias = PFH... Intersection table containing headcount per project and fiscal year)Please forgive the excessive normalization for this example, as I wanted to keep the table structure similar to my real application, which has much more going on.
    In my sample, I have the "Select Criteria" region, where the user specifies the project and fiscal year range that he or she would like to report. Click the Search button, and the report returns the project headcount in a pivoted fashion for the fiscal year range specified.
    I've got it working using a hard-coded query, which is displayed in the "Hardcoded Query" region. In this query, I basically return all years, and set conditions on each column which determines whether that column should be displayed or not based on the range selected by the user. While this works, it is not ideal, as there could be many more fiscal years to account for, and this is not very dynamic at all. Anytime a fiscal year is added to the FISCAL_YEAR table, I'd have to update this page.
    So, after reading all of the OTN SQL pivot forums and "Ask Tom" pivot thread, I've been able to create a second region labeled "Dynamic Query" in which I've created a dynamic query to return the same results. This is a much more savvy solution and works great; however, the column names are generic in the report.
    I had to set the query to parse at runtime since the column selection list is dynamic, which violates SQL rules. Can anyone please help me figure out how I can specify my column names in the dynamic query region to get the same column values I'm getting in the hardcoded region?
    Please let me know if you need anymore information, and many thanks in advance!
    Mark

    Hi Tony,
    Thanks so much for your response. I've had to study up on the dbms_sql package to understand your function... first time I've used it. I've fed my dynamic query to your function and see that it returns a colon delimited list of the column names; however, I think I need a little more schooling on how and where exactly to apply the function to actually set the column names in APEX.
    From my test app, here is the code for my dynamic query. I've got it in a "PL/SQL function body returning sql query" region:
    DECLARE 
      v_query      VARCHAR2(4000);
      v_as         VARCHAR2(4);
      v_range_from NUMBER;
      v_range_to   NUMBER;         
    BEGIN
      v_range_from := :P1_FY_FROM;
      v_range_to   := :P1_FY_TO;
      v_query      := 'SELECT ';
      -- build the dynamic column selections by looping through the fiscal year range.
      -- v_as is meant to specify the column name as (FY10, FY11, etc.), but it's not working.
      FOR i IN v_range_from.. v_range_to  LOOP
        v_as    := 'FY' || SUBSTR(i, 3, 4);
        v_query := v_query || 'MAX(DECODE(FY_NB,' || i || ',PFH_HEADCOUNT,0)) '
          || v_as || ',';
      END LOOP;
      -- add the rest of the query to the dynamic column selection
      v_query := rtrim(v_query,',') || ' FROM ('
        || 'SELECT FY_NB, PFH_HEADCOUNT FROM ('
        || 'SELECT FY_ID, FY_NB FROM FISCAL_YEAR) A '
        || 'LEFT OUTER JOIN ('
        || 'SELECT FY_ID, PFH_HEADCOUNT '
        || 'FROM PROJECT_FY_HEADCOUNT '
        || 'JOIN PROJECT_FY USING (PF_ID) '
        || 'WHERE PL_ID = ' || :P1_PROJECT || ') B '
        || 'ON A.FY_ID = B.FY_ID)';
      RETURN v_query;
    END;I need to invoke GET_QUERY_COLS(v_query) somewhere to get the column names, but I'm not sure where I need to call it and how to actually set the column names after getting the returned colon-delimited list.
    Can you (or anyone else) please help me get a little further? Once again, feel free to login to my host account to see it first hand.
    Thanks again!
    Mark

  • Dynamic UPDATE statement with parameters for column names.

    Hello,
    On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
    On the other hand, in this Re: execute immediate with dynamic column name update and many other
    posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
    dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
    WHERE ST IN
    (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
    '||P_ST||' = CO.ST AND
    CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
    CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
    EXECUTE IMMEDIATE dynSQL ;
    Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
    The compiling works fine and I use Oracle 11g.
    http://psoug.org/definition/EXECUTE_IMMEDIATE.htm

    OK I extracted from all of your posts so far that I have to use "bind-variables with :"
    From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
    set serveroutput on format wraped;
    DECLARE
    dynSQL VARCHAR2(5000);
    P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
    P_ST                VARCHAR2 (100) :='32132';
    BEGIN
    dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
                  WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
                  '||:P_ST||'                           = CO.ST                  AND
                  CO.'||:P_ENT_E_G_NAME||'     > '||:P_ENT_E_G_WE||' AND
                  CO.'||:P_ENT_B_G_NAME||'    
    < '||:P_ENT_E_G_WE||')';
    --this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
    dbms_output.enable;
    dbms_output.put(dynSQL);
    --EXECUTE IMMEDIATE dynSQL;    
    END;Problem:I think I figured it out, the dates that I parse into the query need additional '

  • Creating a Dynamic Update Statement based on Select

    hi,
    i'm trying to create a dynamic update statement based on select statement
    my requirment is to query a joint tables and get the results then based on the results i need to copy all the data and create an update statement for each row
    for ex
    the update statement should look like this
    update iadvyy set SO_SWEEP_CNT = '1' where inst_no = '003' and memb_cust_no = 'aaaaaaaaaaaaaaaa';
    and the select statement like the following
    select substr(key_1,11,9) account_no,sord_mast SO_SWEEP_CNT from
    select acct_no,count(*) sord_mast from
    (select from_acct_no acct_no,update_mast
    from sord where FROM_SYS in ('DEP','INV') and TERM_DATE > 40460
    union all
    select to_acct_no acct_no,update_mast
    from sord where TO_SYS in ('DEP','INV') and TERM_DATE > 40460)
    group by Acct_no)
    right outer join
    invm
    on
    key_1 = '003'||acct_no
    where sord_mast > 0;
    so taking the above two columns from the above select statement and substitue the values as separate update statement.
    is that doable , please share your knowledge with me if poosible
    thanks in advanced

    is that doable , please share your knowledge with me if poosibleyes
    The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the SQL before passing it to EXECUTE IMMEDIATE.
    COPY the statement & PASTE into sqlplus to validate its correctness.

  • Could not reuse TKEY established till expiry, Microsoft DNS refuses Dynamic updates after some minutes

    We are using a DHCP Server that is sending secure (GSS-TSIG based) dynamic updates to Microsoft DNS.
    After successful TKEY negotiation, the dynamic updates are accepted/success.
    Established context is valid for more than 10hours in client side(Based on InitializeSecurityContext output parameter ptsExpiry
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa375507%28v=vs.85%29.aspx)
    But, when we try to use the same TKEY name ( the established context  is not expired)  we are getting "Query Refused error" after some time say 8-10 minutes. Is there any transaction timeout after which client should not reuse the TKEY
    context established ? Whether Microsoft DNS supports TKEY RR with mode 5 ( Delete Security Context/ Key Deletion ) so that client will delete and establish a new context for further DNS updates. Also why BADNAME/BADKEY error is not returned while refusing
    the updates?
    As per the RFC 3645, 
    <RFC snip>
    4.2.1. Terminating a Context
    A server can terminate any established context at any time. The
    server MAY hint to the client that the context is being deleted by
    including a TKEY RR in a response with the Mode field set to 5, i.e.,
    "key deletion" [RFC2930]. An active context is deleted by calling
    GSS_Delete_sec_context providing the associated context_handle.
    </RFC Snip>
    1. Configured Forward Zone aswin.com
    2. Not configured Reverse Zone, so that reverse updates get NOT AUTH ( just to test error case )
    3. TKEY negotiation is successful.
    4. Sent 2 updates say at 19:52 one forward and reverse updates. Forward update is success, Reverse update failed due to reverse zone not configured, which is expected.
    5. Sent 2 updates say at 19:55 using the previously established key, Forward update is success, Reverse update failed due to reverse zone not configured, which is expected.
    6. Sent 2 updates say at 20:01(approximately after 5 minutes), Forward Dynamic update failed with Query Refused. Until  new TKEY negotiation is done all updates are failed with Query Refused. Why the same key could not be used for 10 hours(based on
    Initialize security context output value). Is there any way to find how long key can be reused ?
    Statisctics details from Microsoft DNS
    dnscmd localhost /statistics 00000100
    DNS Server localhost statistics:
    Packet Dynamic Update:
    Updates Received         =          2
        Forwarded            =          0
        Empty (PreCon Only)  =          0
        NoOps (Dups)         =          0
        Rejected             =          1
        Completed            =          1
        Timed Out            =          0
        In Queue             =          0
    Updates Rejected         =          1
        FormError            =          0
        NameError            =          0
        NotImpl              =          0  (Non-Update Zone)
        Refused              =          0
          NonSecure Packet   =          0
          AccessDenied       =          0
        YxDomain             =          0
        YxRRSet              =          0
        NxRRSet              =          0
        NotAuth              =          1
        NotZone              =          0
    Queue
        Queued               =          1
        Retried              =          0
        Timeout              =          0
        In Queue             =          0
    Secure Update
        Success              =          1
        Continue             =          0
        Failure              =          0
          DS Write Failure   =          0
    Update Forwarding
        Forwards             =          0
        TCP Forwards         =          0
        Responses            =          0
        Timed Out            =          0
        In Queue             =          0
    Update Types:
        ZERO       = 0
        A          = 0
        NS         = 0
        CNAME      = 0
        SOA        = 0
        MB         = 0
        MG         = 0
        MR         = 0
        NULL       = 0
        WKS        = 0
        PTR        = 0
        HINFO      = 0
        MINFO      = 0
        MX         = 0
        TXT        = 0
        RP         = 0
        AFSDB      = 0
        X25        = 0
        ISDN       = 0
        RT         = 0
        NSAP       = 0
        NSAPPTR    = 0
        SIG        = 0
        KEY        = 0
        PX         = 0
        GPOS       = 0
        AAAA       = 0
        LOC        = 0
        NXT        = 0
        EID        = 0
        NIMLOC     = 0
        SRV        = 0
        ATMA       = 0
        NAPTR      = 0
        KX         = 0
        CERT       = 0
        A6         = 0
        Unknown    = 0
        Mixed      = 1
    Command completed successfully.
    dnscmd localhost /statistics 00000100
    DNS Server localhost statistics:
    Packet Dynamic Update:
    Updates Received         =         31
        Forwarded            =          0
        Empty (PreCon Only)  =          0
        NoOps (Dups)         =         24
        Rejected             =          3
        Completed            =          4
        Timed Out            =          0
        In Queue             =          0
    Updates Rejected         =          3
        FormError            =          0
        NameError            =          0
        NotImpl              =          0  (Non-Update Zone)
        Refused              =          1
          NonSecure Packet   =          0
          AccessDenied       =          0
        YxDomain             =          0
        YxRRSet              =          0
        NxRRSet              =          0
        NotAuth              =          2
        NotZone              =          0
    Queue
        Queued               =         29
        Retried              =          0
        Timeout              =          0
        In Queue             =          0
    Secure Update
        Success              =          2
        Continue             =          0
        Failure              =          1
          DS Write Failure   =          0
    Update Forwarding
        Forwards             =          0
        TCP Forwards         =          0
        Responses            =          0
        Timed Out            =          0
        In Queue             =          0
    Update Types:
        ZERO       = 0
        A          = 4
        NS         = 0
        CNAME      = 1
        SOA        = 0
        MB         = 0
        MG         = 0
        MR         = 0
        NULL       = 0
        WKS        = 0
        PTR        = 0
        HINFO      = 0
        MINFO      = 0
        MX         = 0
        TXT        = 0
        RP         = 0
        AFSDB      = 0
        X25        = 0
        ISDN       = 0
        RT         = 0
        NSAP       = 0
        NSAPPTR    = 0
        SIG        = 0
        KEY        = 0
        PX         = 0
        GPOS       = 0
        AAAA       = 0
        LOC        = 0
        NXT        = 0
        EID        = 0
        NIMLOC     = 0
        SRV        = 21
        ATMA       = 0
        NAPTR      = 0
        KX         = 0
        CERT       = 0
        A6         = 0
        Unknown    = 0
        Mixed      = 3
    Command completed successfully.
    C:\Users\Administrator>
    -Thanks,
    Devi.U

    Hi Devi,
    Based on this issue, would you please provide the netmon trace to us? I suggest taking a look at this packet. Moreover, please let me know if you tired to update the DNS record via DHCP manually.
    Thank you.
    Best regards,
    Steven Song
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Trying to pivot based on a dynamically created query which generates XML data

    Hi there,
    Hope someone can help
    I'm trying to pivot row data into a pivot type result set where the records for a given employee are pivoted to a single row.
    To do this, I've declared a dynamic query to retrieve the GUID values of the different training course- the actual course names are full of SQL escape characters e.g. ', (,) which I thought might mess up the dynamically generated query
    I've got as far as writing
    DECLARE
    @employeeidsVARCHAR(10)
    DECLARE
    @coursesVARCHAR(max)
    DECLARE
    @queryVARCHAR(max)
    SELECT
      @courses=STUFF((SELECT 
    DISTINCT[TRAIN_ID]
    FROM  
    [Megapay_IWA].[dbo].[HRS_TRAINING]
    FORXMLPATH('')
    ),2,0,'')+']'
    SET
    @query=
    'SELECT * FROM
    (  SELECT t.TRAIN_TRAINING,
       EMPL_EMPLOYEE_ID
            FROM 
    [Megapay_IWA].[dbo].[HRSTRNDONE] as tc
    left  join  Megapay_IWA.dbo.PAYEMPL  as e on tc.TRND_ONRID = e.EMPL_EMPLOYEE_id
    left join [Megapay_IWA].[dbo].[HRS_TRAINING] as t on tc.TRND_TRAIN_ID =t.TRAIN_ID
    ) t
    PIVOT (COUNT(EMPL_EMPLOYEE_ID) FOR TRAIN_ID in
    +@courses+'))
    AS pvt'
    EXECUTE
    (@query)
    which generates a dynamic query along the following lines but how to I update the query to correctly read the train_id values in the xml
    SELECT * FROM
    (  SELECT t.TRAIN_TRAINING,
       EMPL_EMPLOYEE_ID
            FROM 
    [Megapay_IWA].[dbo].[HRSTRNDONE] as tc
    left  join  Megapay_IWA.dbo.PAYEMPL  as e on tc.TRND_ONRID = e.EMPL_EMPLOYEE_id
    left join [Megapay_IWA].[dbo].[HRS_TRAINING] as t on tc.TRND_TRAIN_ID =t.TRAIN_ID
    ) t
    PIVOT (COUNT(EMPL_EMPLOYEE_ID) FOR TRAIN_ID in
    <TRAIN_ID>F607BA64-BD24-4C6F-810E-001E7487FB4B</TRAIN_ID><TRAIN_ID>784EF318-628F-407E-8844-0049E3DD8F86</TRAIN_ID><TRAIN_ID>C7F3B365-7E6C-4CDF-9F0C-010207D1E493</TRAIN_ID><TRAIN_ID>7A82C4C1-5A9F-4EB0-9988-018405D3347A</TRAIN_ID><TRAIN_ID>E3FC88F5-AF5F-4D75-816A-02085190FC5C</TRAIN_ID><TRAIN_ID>BEB39D10-7887-494C-ADCC-0254A1514D06</TRAIN_ID><TRAIN_ID>6D870918-CFA1-4ADA-8427-049FF01902AC</TRAIN_ID><TRAIN_ID>61D1B40A-A9B6-4835-82C4-04FDCCAF7E6D</TRAIN_ID><TRAIN_ID>CA6D6B7-5ACA-4BE0-8A08-0EE87F77F10E</TRAIN_ID><TRAIN_ID>F86E6E93-544E-43F5-A97A-10E96834C781</TRAIN_ID><TRAIN_ID>EB898326-705F-4E70-B7BB-119B8953DFA9</TRAIN_ID><TRAIN_ID>491BFC77-0FA9-42C5-A255-11C49AA28CDD</TRAIN_ID><TRAIN_ID>C7A972FB-1E73-41FC-A4EF-12F5811C9853</TRAIN_ID><TRAIN_ID>3FD2CEE3-E85F-4624-87D7-13767D2DB391</TRAIN_ID><TRAIN_ID>F8A784C0-6E56-4769-92D2-1480BCAB2BEA</TRAIN_ID><TRAIN_ID>60D36A51-E642-40A2-A2F7-14D158B59781</TRAIN_ID><TRAIN_ID>67ED29A3-E2AD-42EC-8312-156084C0BB26</TRAIN_ID><TRAIN_ID>64B637B9-CC7D-47C8-9220-15D5FA76E65F</TRAIN_ID><TRAIN_ID>59B5D61C-4228-485D-89EE-185B74E42F3C</TRAIN_ID>
    Note I'm also fine with updating the dynamic query to generate a statement that generates a normal where in constraint e.g.
    PIVOT (COUNT(EMPL_EMPLOYEE_ID) FOR TRAIN_ID in
    ('F607BA64-BD24-4C6F-810E-001E7487FB4B','784EF318-628F-407E-8844-0049E3DD8F86')
    Thanks
    John

    Thanks guys, that helped immensely,
    For the record here is the slightly modified version [made generic to show the overall principle] that got it working for me in the end
    DECLARE @ColumnList VARCHAR(MAX) = '';
    DECLARE @query VARCHAR(max);
    WITH Data AS (
            SELECT columnname
             FROM    dbo.table
             SELECT         @ColumnList +='[' +  [columnname] +'],'
             FROM         Data;
    SET @ColumnList = STUFF(@ColumnList, 2, 0, '');
    SET @ColumnList = LEFT(@ColumnList, LEN(@ColumnList) - 1)
    --print @columnlist
    SET @query=
    'SELECT otherfields, ' +@ColumnList +' FROM
    (  SELECT   otherfields,columnname, datefield
             FROM        dbo.table
    ) t
    PIVOT (max(datefield) FOR [columnname] in (' +@ColumnList + ')
    ) AS pvt'
    execute (@query)

  • Update Query using Toplink

    I would like to fire an update query using Toplink mapping objects. The
    structure of the Query would be like
    update <<table name>>
    set <<col name A>> = 'Y'
    where <<col name B>> in (<<valA>>,<<valB>>............);
    ValA, ValB.... are dynamic values passed from my front end Java App
    Can anyone help me in this regard...........
    Thanks
    Karthik

    Karthik,
    This is new functionality added in 10.1.3. You will want to look at UpdateAllQuery.
    Doug

  • Dynamic Updation!!!!

    Hi All,
    I am new to j2me and i have some basic query..plz help me!!!
    In J2ME Can we install a jar file into lib folder of an existing application(Dynamic Updation).
    Say we have an application that provides encryption facility using an algorithm that was available at the time of application developemnt.But Now we have a much better algorithm so i want provide my customer this new algorithm.So that i will pack this new set of algorithm in a jar file and install it into the lib folder of my already existing application.My Application will check the presence of this new jar file and will start using it. Is this possible in j2me?
    Thanks in Advance
    Ravi

    You cannot do that. A midlet can only be stored in a singe Jar file. If you update, you'll have to update the complete midlet. You could do that using OTA, but I don't know if that is widely supported.

  • Insert and update query to calculate the opening and closing balance

    create table purchase(productid number(5) ,dateofpurchase date,
    qty number(5));
    create table inventory(invid number(5),productid number(5),
    idate date,openingqty number(5),closingqty number(5));
    Records in inventory:
    1,1,'01-jan-2009', 10, 20
    2,1,'03-jan-2009', 20, 30
    3,1,'04-jan-2009', 40, 50
    when I enter the purchase invoice for 15 qty on 02-jan-2009
    after say '15-jan-09' , a new record should get inserted
    with opening balance = (closing balance before 02-jan-2009)
    and all the opening and closing balance for that product should
    get affected.
    If the invoice for 20 qty is entered for the existing date say
    '03-jan-2009' in inventory , then the closing balance
    for 03-jan-2009 should get updated and all the following records
    should get affected.
    I need the insert for the first one and update query for the
    second one.
    Vinodh

    <strike>You can do this in one statement by using the merge statement</strike>
    Hmm, maybe I spoke too soon.
    Edited by: Boneist on 25-Sep-2009 13:56
    Thinking about it, why do you want to design your system like this?
    Why not simply have your purchases table hold the required information and then either work out the inventory on the fly, or have a job that calls a procedure to add a row for the previous day?
    If you continue with this design, you're opening yourself up to a world of pain - what happens when the data doesn't match the purchases table? Also when is the inventory cut-off to reset the opening/closing balances? Monthly? Annually? Weekly? If it's set to one of those, what happens when the business request the inventory for a particular week?
    Edited by: Boneist on 25-Sep-2009 13:59

  • If then else in update query

    Hello,
    I was hoping anyone could provide ideas on the best way to do an update query based on an if then else statement I am using Oracle 11 on a linux server. I am writing within a perl script. I've researched online and saw some examples using case. Below is the basic query logic I am trying to implement. I would really appreciate any suggestions.
    Thanks,
    JC
    If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') and askme_temp.CKT_ID = heci.CKT_ID then SUBPRODUCT =’IPAG’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') AND REGION=’SE’ then SUBPRODUCT =’METRO_E’
    ELSE If the MAINT_CENTER IN ('ENOC1CENTER','PMCTGAAHSDC','ATTCSPCRT01','ATTCSPCWS01','NTNLWHS4NSA') AND CAC1=’S’ and substring(CKT_ID,4,2) IN ('KQ','KR','KS','KP','L1','L2','L3','VL') then SUBPRODUCT =’OPT_E_MAN’

    Hi,
    Welcome to the forum!
    CASE sounds like a good idea to me.
    For example:
    UPDATE     table_x
    SET     subproduct = CASE
                   WHEN  askme_temp.CKT_ID = heci.CKT_ID
                         THEN  'IPAG'
                   WHEN  region          = 'SE'
                         THEN  'METRO_E'
                         ELSE  'OPT_E_MAN'
                   END
    WHERE     maint_center     IN ( 'ENOC1CENTER'
                      , 'PMCTGAAHSDC'
                      , 'ATTCSPCRT01'
                      , 'ATTCSPCWS01'
                      , 'NTNLWHS4NSA'
    AND   cac1                  = 'S'
    AND   SUBST (ckt_id, 4, 2)  IN ('KQ', 'KR', 'KS', 'KP', 'L1', 'L2', 'L3', 'VL')
    AND   ...
    ;CASE expressions are evaluated in the order in which you write them, so if askme_temp.ckt_id = heci.ckt_id (whatever those things are), subproduct will be set to 'IPAG'. It won't matter whether region is 'METRO_E' or not; if the 1st condition is TRUE, the first THEN value is returned, and the other WHEN expressions aren't even evaluated.
    What do you want to do if none of those conditions are met?
    Any conditions that are common to all the rows being UPDATEd can be put in the WHERE clause; they don't have to be repeated in the CASE expression.
    Remember, MERGE is often more convenient to use than UPDATE.
    Edited by: Frank Kulash on Jul 27, 2011 3:23 PM

  • About update query

    Hello :),
    I am a MS SQL Server expert [;)]. trying to learn ORACLE.
    I tried to assign some value to a variable in an update query. I got error message that virtual columns are not allowed. This is very important to get rolling effect.
    Can some one please guide me about how to get rolling effect if we can not assign a value to a variable in an update query.
    Thanx in advance.
    Nishu

    hello sgalaxy and gintsp, thanx for ur reply.
    My reply is so late because for some reason I was not able to log on to this site.
    There is some good reason why I need this. I am giving code and error messages below, please guide me.
    ==============================
    I am trying this thing in procedure. I am using ORACLE DATABASE EXPRESS EDITION
    Here is the code.
    create or replace procedure "PROC1"
    is
    TYPE Bal_Collect IS TABLE OF NUMBER;
    Collt Bal_Collect := Bal_Collect(100);
    begin
    Update empAccount Set Bal = Collt(Collt.Last) Returning Bal BULK COLLECT INTO Collt;
    end;
    Error message
    Compilation failed,line 6 (02:20:45)
    PLS-00425: in SQL, function argument and return types must be SQL type
    Compilation failed,line 6 (02:20:45)
    PL/SQL: ORA-00904: : invalid identifier
    Compilation failed,line 6 (02:20:45)
    PL/SQL: SQL Statement ignored
    BUT FOLLOWING UPDATE STATEMENT WORKS
    Update empAccount Set Bal = Collt(1) Returning Bal BULK COLLECT INTO Collt;

  • Update query not working from edit page

    Next incident with the guestbook saga:
    Successful execution of gb_entry_mstr_det_e.cfm with URL:
    http://www.benoitsystems.com/ww/bd/gb/gb_entry_mstr_det_e.cfm?call_number=14 all have database current info...this is good, but:
    textboxes
    Problem 1:
    the SELECT field does not does not reflect/display the correct option I know exists in the database
    the database field whence this SELECT object is supposed to display is a number, not text.
    now,...
    Problem 2:
    Clicked on "Update Your Entry" button at bottom of edit page (to update by going to gb_confirm_update.cfm)
    <INPUT
    TYPE="submit"
    NAME="submit"
    VALUE="Update Your Entry">
    then, arriving at the gb_confirm_update.cfm page, ...
    Got an error (below) executing the page: gb_confirm_update.cfm with resulting URL:
    http://www.benoitsystems.com/ww/bd/gb/gb_confirm_update.cfm?call_number=#gb_entryID#
    --- snippet from template gb_confirm_update.cfm
    <CFQUERY DATASOURCE="9130.ww" NAME="ww_gb_ud">
    UPDATE gb_entries
    SET
    gb_entry_stts_='form.gb_entry_stts_',
    gb_entry_nm_f='form.gb_entry_nm_f',
    gb_entry_nm_l='form.gb_entry_nm_l',
    gb_entry_nm_l_dspl_x=form.gb_entry_nm_l_dspl_x,
    gb_entry_tce='form.gb_entry_tce',
    gb_entry_tce_dspl_x=form.gb_entry_tce_dspl_x,
    gb_entry_cy='form.gb_entry_cy',
    gb_entry_stt='form.gb_entry_stt',
    gb_entry_instr='form.gb_entry_instr',
    gb_entry_m='form.gb_entry_m',
    gb_entry_del_x=form.gb_entry_del_x
    WHERE gb_entryID=form.gb_entryID
    </CFQUERY>
    --- end snippet ---
    =================================================
    Error Executing Database Query. 
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4. 
    The error occurred in E:\benoitsystems.com\wwwroot\ww\bd\gb\gb_confirm_update.cfm: line 2
    1 : <!--- <CFUPDATE DATASOURCE="9130.ww" TABLENAME="gb_entries"> --->
    2 : <CFQUERY DATASOURCE="9130.ww" NAME="ww_gb_ud">
    3 : UPDATE gb_entries
    4 : SET
    SQL    UPDATE gb_entries SET gb_entry_stts_='form.gb_entry_stts_', gb_entry_nm_f='form.gb_entry_nm_f', gb_entry_nm_l='form.gb_entry_nm_l', gb_entry_nm_l_dspl_x=form.gb_entry_nm_l_dspl_x, gb_entry_tce='form.gb_entry_tce', gb_entry_tce_dspl_x=form.gb_entry_tce_dspl_x, gb_entry_cy='form.gb_entry_cy', gb_entry_stt='form.gb_entry_stt', gb_entry_instr='form.gb_entry_instr', gb_entry_m='form.gb_entry_m', gb_entry_del_x=form.gb_entry_del_x WHERE gb_entryID=form.gb_entryID 
    DATASOURCE   9130.ww
    VENDORERRORCODE   -3010
    SQLSTATE   07002
    Please try the following:
    Check the ColdFusion documentation to verify that you are using the correct syntax.
    Search the Knowledge Base to find a solution to your problem.
    Browser   Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
    Remote Address   71.233.234.226
    Referrer   http://www.benoitsystems.com/ww/bd/gb/gb_entry_mstr_det_e.cfm?call_number=14
    Date/Time   21-Jul-10 03:11 PM
    =================================================
    I have every NAME of each object matching, verbatum, in the UPDATE query, and every database field name correct in teh query also.

    I was encouraged to send snippets in an another submission, and now I believe it is best that I  "lay my cards on the table"
    Here's my hand:
    Pages in question for your review:
    http://www.benoitsystems.com/ww/bd/gb/gb_mstr.cfm  click on the pencil (the toilet will delete the record.
    http://www.benoitsystems.com/ww/bd/gb/gb_entry_mstr_det_e.cfm?call_number=21  go to bottom of webpage and click “Update Your Entry”
    http://www.benoitsystems.com/ww/bd/gb/gb_confirm_update.cfm?call_number=#gb_entryID#
    In your review of the above (should you choose) before clicking on the pencil, look at the status on the master listing record you will be editing, and feel free to edit.  Most statuses will be “Hold”
    Two dummy MS Access database tables:
    Table 1: "gb_entries" (Guestbook)
    field 1: gb_entries_ID (Autonumber - Long Integer)
    field 2: gb_entries_dt (date/time)
    field 3: gb_entries_nm_f (Text)
    field 4: gb_entries_nm_l (Text)
    field 5: gb_entries_nm_stts_ (Number field - Byte (not bit)) (fed by gb_sttsID)
    couple other text fields
    field 6: gb_entries_em (Text)
    field 7: gb_entries_cy (Text)
    field 8: gb_entries_stt (Text)
    field 9: gb_entries_nm_l_dspl (Yes/No or True/False)
    field 10: gb_entries_m (Memo type)
    Table 2: "gb_stts_rf" (Guestbook Status Reference)
    field 1: gb_sttsID (Autonumber - Long Integer)
    field 2: gb_stts (Text)
    Two Templates:
    This is the edit page (where a person with administrative access may edit the status or change the spelling for someone, etc.):
    <!--- This query fills the form with the chosen record data (except for the darned SELECT object) ---> <CFQUERY NAME="edit_entry" DATASOURCE="9130.ww"> SELECT * FROM gb_entries WHERE #call_number#=gb_entryID </CFQUERY>
    <!--- This query is for the select dropdown of guestbook status options (set to default on “Hold” from gb_nw.cfm) ---> <CFQUERY NAME="q_stts" DATASOURCE="9130.ww"> SELECT * FROM gb_stts_rf </CFQUERY>
    <HTML>
    <HEAD>
    <TITLE>Woodwindology Guestbook Entry Edit Page</TITLE> <CFOUTPUT QUERY="incl_css_bd">#incl_code#</CFOUTPUT>
    </HEAD>
    <BODY
          BGPROPERTIES="fixed">
    <DIV ALIGN="center">
    <IMG
          SRC="<CFOUTPUT>#baseurl#</CFOUTPUT>md/img/ut/ttl/pg/guestbook.gif"
          BORDER="0">
    <BR>
    <IMG
          SRC="<CFOUTPUT>#baseurl#</CFOUTPUT>md/img/ut/ttl/sub/edit_entry.gif"
          BORDER="0">
    <BR>
    Developer View
    </DIV>
    <TABLE>
          <TR>
                <TD>
                      <TABLE
                            WIDTH="100%"
                            BORDER="0"
                            CELLPADDING="5"
                            CELLSPACING="0">
          <TR>
                <TD VALIGN="top">
                      <FORM
                            NAME="f_gb_entry_mstr"
                            ACTION="gb_confirm_update.cfm?call_number=#gb_entryID#"
                            METHOD="post">
                      <CFOUTPUT QUERY="edit_entry">
                      <B>Entry ID:</B>
                      #gb_entryID#     
                      <INPUT
                            TYPE="hidden"
                            NAME="gb_entryID"
                            VALUE="#gb_entryID#">
                      <P>
                      <B>Entry Date and Time:</B>
                      #DateFormat("#gb_entry_dt#","mmmm d, yyyy")# #TimeFormat("#gb_entry_dt#","h:mm tt")#
    <P>
                      <B>Entry Status:</B>
                      <SELECT
                            NAME="gb_entry_stts_"
                            VALUE="#gb_entry_stts_#">
    </CFOUTPUT>
                            <CFOUTPUT QUERY="q_stts">
                                  <OPTION VALUE="#gb_sttsID#">#gb_stts#</OPTION>
                            </CFOUTPUT>
                      </SELECT>
                      <P>
    <CFOUTPUT QUERY="edit_entry">
                      <B>Guest's First Name:</B>
                      <INPUT
                            TYPE="text"
                            NAME="gb_entry_nm_f"
                            VALUE="#gb_entry_nm_f#">
                      <P>
                      <B>Guest's Last Name:</B>
                      <INPUT
                            TYPE="text"
                            NAME="gb_entry_nm_l"
                            VALUE="#gb_entry_nm_l#">
                      <BR>
                      Display Last Name:
                      <INPUT
                            TYPE="radio"
                            NAME="gb_entry_nm_l_dspl_x"
                            VALUE="Yes">
                      Do Not Display Last Name:
                      <INPUT
                            TYPE="radio"
                            NAME="gb_entry_nm_l_dspl_x"
                            VALUE="no">
                            <P>
                            <B>Your Email Address:</B><BR>
                            <INPUT
                                  TYPE="text"
                                  NAME="gb_entry_tce"
                                  VALUE="#gb_entry_tce#"
                                  SIZE="40"
                                  MAXLENGTH="40">
                      <BR>
                      Uncheck the box to keep email private:
                      <INPUT
                            TYPE="checkbox"
                            NAME="gb_entry_tce_dspl_x"
                            VALUE="#gb_entry_tce_dspl_x#">
                      <P>
                      <SPAN CLASS="emph01">*</SPAN> Your City:
                      <INPUT
                            TYPE="text"
                            NAME="gb_entry_cy"
                            VALUE="#gb_entry_cy#"
                            SIZE="30">
                      <P>
                      <SPAN CLASS="emph01">*</SPAN> Your State:
                      <INPUT
                            TYPE="text"
                            NAME="gb_entry_stt"
                            VALUE="#gb_entry_stt#"
                            SIZE="30">
                      <BR>
                            <B>Instruments Played:</B>
                      <BR>
                            <TEXTAREA
                                  COLS="45"
                                  MAX="50"

Maybe you are looking for

  • Error while importing a table with BLOB column

    Hi, I am having a table with BLOB column. When I export such a table it gets exported correctly, but when I import the same in different schema having different tablespace it throws error IMP-00017: following statement failed with ORACLE error 959: "

  • How to use the XSLT SE in  a composite application

    (The new XSLT SE as of July.) I followed the setup using the XSLT wizard in Netbeans and the xsltse driver-tests out of the open-jbi-components checkout and now I am stuck. Kevan points out that BPEL and partnerlinks are no longer needed, so I'm not

  • When selling my iPhone 5, what do I need to do?

    So I have decided to sell my new iPhone 5 and go back to the 4. I have performed all the necessary resets and have wiped out all the information. My question, is there anything special I need to to regarding the sim card and the LTE? I don't want the

  • Adding a goemetry object in an already started applet, behvior ?

    Hello there, I would like to add a geometric form (cube, box, cone etc..) in an already started applet. I think creating a specific behavior would be the most appropriate. Has anybody done this kind of thing before ? Many thanks. Gwena�l

  • Is there a way to zoom images in and out without changing the frame?

    It is easy to move an image around within a frame without touching the frame, but I have not found a way to zoom in and out without touching the frame. I'm working with a lot of images (Indesign CS6 for PC) and I need to do this a lot. Thanks.