Help in Update Query

Hi, I want to update status_code of table_2. T_ID is the primary key in both table (Table_1 and table_2). The condition is any person's age >70 then status_code should be 'R' and if person's age<70 then status_code should be 'N'. Please help on this
Update query.
/*Table_1*/
T_ID  LASTNAME  FIRSTNAME   DOB
1001 KAISER      SUJIR    01/01/1942
1002 SMITH     HUJR       01/01/1948
1003 JOHN      JANE       02/01/1958
/*Table_2*/
T_ID  LASTNAME  FIRSTNAME   STATUS_CODE
1001 KAISER      SUJIR    R
1002 SMITH     HUJR       R
1003 JOHN      JANE        R
/*Need the Following Result after the Update*/
T_ID  LASTNAME  FIRSTNAME   STATUS_CODE
1001 KAISER      SUJIR    R   --The Age is >70 that's why status_code is 'R'
1002 SMITH     HUJR       N  --The Age is <70
1003 JOHN      JANE        N  --The Age is <70

DECLARE @table1 TABLE (T_ID INT, lastName VARCHAR(30), firstName VARCHAR(30), dob DATE)
INSERT INTO @table1 (T_ID, lastName, firstName, dob) VALUES (1001, 'KAISER', 'SUJIR' ,'01/01/1942'),(1002, 'SMITH', 'HUJR', '01/01/1948'),(1003, 'JOHN', 'JANE', '02/01/1958'),(1004, 'Jack', 'Jackson', '12/03/1944')
DECLARE @table2 TABLE (T_ID INT, lastName VARCHAR(30), firstName VARCHAR(30), statusCode CHAR(1))
INSERT INTO @table2 (T_ID, lastName, firstName, statusCode) VALUES (1001, 'KAISER', 'SUJIR', 'R'),(1002, 'SMITH', 'HUJR', 'R'),(1003, 'JOHN', 'JANE', 'R'),(1004, 'Jack', 'Jackson', 'R')
-- tables set up
UPDATE @table2
SET statusCode = CASE WHEN DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP) - CASE WHEN DATEADD(YEAR,DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP),t1.dob) > CURRENT_TIMESTAMP THEN 1 ELSE 0 END >= 70 THEN 'R' ELSE 'N' END
FROM @table2 t2
INNER JOIN @table1 t1
ON t2.T_ID = t1.T_ID
SELECT *, DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP) - CASE WHEN DATEADD(YEAR,DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP),t1.dob) > CURRENT_TIMESTAMP THEN 1 ELSE 0 END
FROM @table2 t2
INNER JOIN @table1 t1
ON t2.T_ID = t1.T_ID

Similar Messages

  • Help on update query

    Just wanna ask help in update query
    SELECT T1.ttl_cr_adjust_amt,T2.ttl_cr_adjust_amt
    FROM invoice T1
    ,(SELECT bill_date
    ,acct_no
    ,sum(summ_amt) as ttl_cr_adjust_amt
    FROM INV_ACCT_SUMM
    WHERE summ_code='LSG02'
    GROUP by bill_date,acct_no) T2
    WHERE T1.bill_date=T2.bill_date
    AND T1.acct_no=T2.acct_no
    i want update T1.ttl_cr_adjust_amt= T2.ttl_cr_adjust_amt tht means i want give T2.ttl_cr_adjust_amt to T1.ttl_cr_adjust_amt the primary key for invoice is T1.bill_date,T1.acct_no
    how to do update stament
    i need efficent
    thanks is can help

    Be care, simpe UPDATE without WHERE clause will change ALL rows in
    invoice table dispite are there any related data in inv_acc_summ.
    (NOT tested !!!)
    UPDATE invoice T1
    SET T1.ttl_cr_adjust_amt = (SELECT sum(summ_amt)
    FROM INV_ACCT_SUMM T2
    WHERE summ_code='LSG02'
    AND T1.bill_date=T2.bill_date
    AND T1.acct_no=T2.acct_no
    WHERE (t1.bill_date, t1.acc_no) IN
    SELECT t2.bill_date, t2.acc_no
    FROM INV_ACCT_SUMM t2
    WHERE t2.summ_code='LSG02'
    Rgds.

  • Need help with update query

    I am having a strange problem with an update query I am running. Here are the specifics:
    1. I run a script that extracts qualifying rows form a source table (S1), performs some calculation,s and stores the results in a temporary table (T1).
    2. The calculations stored in the temporary table (T1) are only for a subset of rows in the source table (S1).
    3. The temporary table (T1) uses the same primary key values as the source table (T1).
    4. Once the calculations are completed, I want to update a single column on the source table (S1.CalcValue) with the calculated value from the temporary table (T1.CalcValue).
    The problem is that I am doing monthly updates so I run month 1, do some verification of the data and then update the source table. Then repeat the process for months 2 through n. When I run the update for the month 2 data, the prior month 1 data for the column is lost. Below is the update script which looks like it should work and only update on the matching keys between the temporary table (T1) and the source table (S1). I was wondering if anyone could let me know what is wrong with this script and why.
    I am new to Oracle having worked extensively in SQL Server, so the syntax differences are killing me right now so any help would be appreciated.
    Update script:
    procedure update_rvu AS
    BEGIN
    --update the test.RVU table
    update test.RVU S1
    set S1.CalcRVU = ( select
    T1.CalcRVU
    from
    TMP_RVU T1
    where
    S1.GroupId = T1.GroupId
    and
    S1.PatientId = T1.PatientId
    and
    S1.InvoiceId = T1.InvoiceId
    and
    S1.TransId = T1.TransId
    commit;
    END update_rvu;
    Edited by: user9009311 on Apr 14, 2010 4:47 PM

    Most likely you want a WHERE clause in your update portion ... something like
    update test.RVU S1
    set S1.CalcRVU = ( select
    T1.CalcRVU
    from
    TMP_RVU T1
    where
    S1.GroupId = T1.GroupId
    and
    S1.PatientId = T1.PatientId
    and
    S1.InvoiceId = T1.InvoiceId
    and
    S1.TransId = T1.TransId
    where exists
       select null
       from tmp_rvu t11
       where S1.GroupId = T11.GroupId
       and    S1.PatientId = T11.PatientId
       and    S1.InvoiceId = T11.InvoiceId
       and    S1.TransId = T11.TransId
    )You can also look into using the MERGE command (if you're on version 10 or better you can perform update only operations with it). I personally find it more 'friendly' than correlated updates a lot of the time.

  • Help with Update query including JOIN

    Hi,
    This is my first post to this forum and really hoping someone is able to help me write an update query.
    Here is my data model:
    Table (Columns)
    Services (ServiceCode, BranchID, GLCodeGUID)
    GLCodes (GLCodeGUID, BranchID, GLCode)
    I have added valid GLCode data to the Services table for BranchID = 99
    I would like to update all other branch records in the service table to their corresponding GLCodeGUID values  matched by GLCode.
    This is the query I have come up with so far which is incorrect.
    UPDATE S
    SET S.GLAccountCodeGUID = G.GLCodeGUID
    FROM Services S
    JOIN GLCodes G
    ON G.GLCodeGUID = S.GLAccountCodeGUID
    JOIN Services SM
    ON S.ServiceCode = SM.ServiceCode and SM.BranchID = 99
    WHERE S.BranchID != 99
    AND S.IsActive = 1
    ORDER BY S.ServiceCode

    Received some assistance from a work colleague and solved this with the following Query:
    UPDATE s2 SET s2.GLAccountCodeGUID = gl2.GLCodeGUID
    FROM Services s1
    JOIN GLCodes gl1
    ON s1.GLAccountCodeGUID = gl1.GLCodeGUID
    JOIN GLCodes gl2
    ON gl1.GeneralLedgerCode = gl2.GeneralLedgerCode AND gl1.BranchID <> gl2.BranchID
    JOIN Services s2
    ON s1.ServiceCode = s2.ServiceCode AND s1.ServiceCode = s2.ServiceCode AND s1.BranchID <> s2.BranchID
    WHERE s1.BranchID = 99 AND gl1.BranchID = 99 AND
    s2.BranchID = 2 AND gl2.BranchID = 2

  • Help with Update Query -

    I am trying to run the following update query:
    update emp
    set emp.COMM = 500
    where emp.deptno = (select dept.deptno
    from dept
    where dept.loc = 'BOSTON'
    or dept.loc ='NEW YORK')
    SQL/Navigator returns:
    ORA-01427 - Single Row Subquerty Returns More than one row.
    How do I change the query so it will process with multiple return rows on the subquery?
    The help text specified I used the ANY, ALL, IN, or NOT IN to specify which values to compare. Any body have an example of this?

    Try this:
    update emp
    set emp.COMM = 500
    where emp.deptno IN (select dept.deptno
    from dept
    where dept.loc = 'BOSTON'
    or dept.loc ='NEW YORK')

  • Help simple update query

    Hi all,
    I have a simple update query problem. I have four tables
    activist(activist_id,first_name,last_name,c_state),
    membership(activist_id,g_n_id),
    group_network(g_n_id,g_n_type_id),
    school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
    Here is the query for the states which are null
    select distinct a.activist_id,a.first_name,a.last_name,
    a.c_state,sd.state from activist a,membership m,
    group_network g,school_group_det sd where
    a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
    g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
    order by a.activist_id
    I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
    Pleae any one help me
    Thanks
    Srinivas

    Hi all,
    I have a simple update query problem. I have four tables
    activist(activist_id,first_name,last_name,c_state),
    membership(activist_id,g_n_id),
    group_network(g_n_id,g_n_type_id),
    school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
    Here is the query for the states which are null
    select distinct a.activist_id,a.first_name,a.last_name,
    a.c_state,sd.state from activist a,membership m,
    group_network g,school_group_det sd where
    a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
    g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
    order by a.activist_id
    I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
    Pleae any one help me
    Thanks
    Srinivas

  • Need help on Update query

    Hi,
    I have 2 tables A and B with below data and description, i want to update Table B when C1, C2 are equal and C3 is not equal by comparing with Table A. If A contains 2 records with same such condition then update any 1 record's different description in Table B.
    I can achieve this by using below query but i don't want to query Table A twice. Also if this is update is possible using Cursor is also fine for me..
    Please help me on this...Thanks in Advance
    Query
    Update B
    set B.c3 = (select c3 from A
    where A.c1 = B.c1
    and A.c2 = B.c2
    and A.c3 <> B.c3
    and ROWNUM = 1)
    where exists (select 1 from A
    where A.c1 = B.c1
    and A.c2 = B.c2
    and A.c3 <> B.c3);
    Table A Table B
    C1 C2 C3 C1 C2 C3
    1 B desc1 1 B desc3
    1 B desc2 2 x desc2
    2 x desc1 3 y desc3
    3 y desc3
    Expected Output
    Table B
    C1 C2 C3
    1 B desc1 or desc2 (any 1 different description should get updated)
    2 x desc1
    3 y desc3

    I am a bit confused. this also works without numbers in the C3 column.
    drop table tablea;
    drop table tableb;
    create table tablea as
    (select 1 C1,'B' C2, 'descA' C3 from dual union
    select 1, 'B', 'descB' from dual union
    select 2, 'x', 'descC' from dual union
    select 3, 'y', 'descC' from dual
    create table tableb as
    (select 1 C1,'B' C2, 'descC' C3 from dual union
    select 2, 'x', 'descB' from dual union
    select 3, 'y', 'descC' from dual
    merge into tableb t1
    using (
               select tablea.C1, tablea.C2, max(tablea.C3) C3
               from tablea, tableb
               where tablea.c1 = tableb.c1
               and     tablea.c2 = tableb.c2
               and     tablea.c3 != tableb.c3
               group by tablea.C1, tablea.C2) t2
      on (t1.C1 = t2.C1 and t1.C2 = t2.C2 )
    when matched  then
    update
    set T1.C3 = t2.C3;
    select * from tableb;
    C1     C2     C3
    1     B     descB
    2     x     descC
    3     y     descC

  • Help for update query

    Hi, How I can split the column of code_full_desc and update in code1,code2 and code3 column which are blank. It should be split after first hyphen.
    create table #desc (code_full_desc char(20), code1 char(4),code2 char(4), code3 char(6))
    insert into #desc values ('CCCCA_AAAA_99_ECTRA','','','')
    insert into #desc values ('DDDDA_BBBB_88_TRACT','','','')
    ---Results should be
    code_full_desc                  code1   code2   code3
    CCCCA_AAAA_99_ECTRA     AAAA   99        ECTRA
    DDDDA_BBBB_88_TRACT      BBBB    88       TRACT

    create table #desc (code_full_desc char(20), code1 char(4),code2 char(4), code3 char(6))
    insert into #desc values ('CCCCA_AAAA_99_ECTRA','','','')
    insert into #desc values ('DDDDA_BBBB_88_TRACT','','','')
    select * from #desc
    ;with mycte as
    SELECT row_number() Over(Partition by code_full_desc Order by code_full_desc) rn, code_full_desc, S.a.value('(/H/r)[4]', 'VARCHAR(100)') AS splitVal4
    , S.a.value('(/H/r)[3]', 'VARCHAR(100)') AS splitVal3
    , S.a.value('(/H/r)[2]', 'VARCHAR(100)') AS splitVal2
    , S.a.value('(/H/r)[1]', 'VARCHAR(100)') AS splitVal1
    ,code1,code2,code3
    FROM
    SELECT *,CAST (N'<H><r>' + REPLACE(code_full_desc, '_', '</r><r>') + '</r></H>' AS XML) AS [vals]
    FROM #desc) d
    CROSS APPLY d.[vals].nodes('/H/r') S(a)
    Update mycte
    set
    code1=splitVal2,
    code2=splitVal3,
    code3=splitVal4
    WHERE rn=1
    select * from #desc
    drop table #desc

  • Need help in UPDATE data in SQL Query

    Hi all,
    I am trying to update data in the sql table as per below screenshot but couldn't able to do it. Can anyone help to update the data as I mention in screenshot.Appreciate you help.Thanks.
    Yellow highlighted columns are source
    Green highlighted columns are target
    Colored data should be update as per source data in sql table.Data is not static as it might have more rows to update and query should be bit dynamic.
    Maruthi...

    You have already asked this question once. You did not get any good answers, because you the information you gave was insufficient. And I'm afraid that the information is still in sufficient.
    Or more exactly, from the example you have given, the answer is: can't be done. And the reason it can't be done, is as I explained in response to you first thread: there is no information in the data to from which we can deduce that Clorox Company
    should be under "Week 1-1,K.B,F". The fact that rows are listed in a certain order in the screenshoot is of no importance, because a table is an unordered object.
    But you said in another post that you have a timestamp column. Maybe that column is usable - maybe it is not. But at least it is a key that you have more columns that the ones you show.
    The best way to get help with this type of problems is to post:
    1) CREATE TABLE statement for your table(s).
    2) INSERT statements with sample data.
    3) The desired result given the sample.
    4) A short description of the actual buisness problem you are trying to solve.
    5) Which version of SQL Server you are using.
    This makes it easy to copy and paste into a query window to develop a tested solution. Screenshots with an insufficient amount of data is not going to help you very much.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Help in update generic query

    HI, Some super_id is wrong or null in my #cred table and I want to update with the correct super_id.
    The best way is to COUNT max 'super_id' on the basis of column-'b_id' and 'bid_code'.
    Query condition should be based on 'b_id' and 'bid_code'. Please help for the logic of this update query.
    I want also add the column of 'Correct super_id is:' in the result with the correct super_id.
    Tip. 'b_id' column data must exist in  'bid_code' column. Can we use like command to avoid any hard code in the update and create generic script for update.
    Example of new column of 'Correct super_id is:
    The record of b_id-'SLEP' and bid_code-'SLEP_LEN' has super_id-'2' three times, one time is '1' and one time is 'null'.
    So max super_id is 2 for these and this is correct super_id.
    drop table #cred
    create table #cred (unique_id numeric,b_id char(10), bid_code char(10), super_id numeric)
    insert into #cred values (10012,'SLEP','SLEP_LEN',2)
    insert into #cred values (10013,'SLEP','SLEP_LEN',1)
    insert into #cred values (10014,'SLEP','SLEP_LEN',2)
    insert into #cred values (10015,'SLEP','SLEP_LEN',2)
    insert into #cred values (10016,'SLEP','SLEP_LEN',null)
    insert into #cred values (10017,'GHEP','GHEP_RET',44)
    insert into #cred values (10018,'GHEP','GHEP_RET',44)
    insert into #cred values (10019,'GHEP','GHEP_RET',44)
    insert into #cred values (10020,'GHEP','GHEP_RET',22)
    insert into #cred values (10021,'GHEP','GHEP_RET',null)
    insert into #cred values (10022,'SDEP','SDEP_Full',77)
    insert into #cred values (10023,'SDEP','SDEP_Full',77)
    insert into #cred values (10024,'SDEP','SDEP_Full',55)
    insert into #cred values (10025,'SDEP','SDEP_Full',77)
    insert into #cred values (10026,'SDEP','SDEP_Full',null)
    Select * from #cred order by unique_id
    --Desired Results
    unique_id    b_id    bid_code    super_id   Correct super_id is:
    10012    SLEP          SLEP_LEN      2
    10013    SLEP          SLEP_LEN      1             2
    10014    SLEP          SLEP_LEN      2
    10015    SLEP          SLEP_LEN      2
    10016    SLEP          SLEP_LEN      NULL       2
    10017    GHEP          GHEP_RET      44       
    10018    GHEP          GHEP_RET      44
    10019    GHEP          GHEP_RET      44
    10020    GHEP          GHEP_RET      22          44
    10021    GHEP          GHEP_RET      NULL      44
    10022    SDEP          SDEP_Full     77
    10023    SDEP          SDEP_Full     77
    10024    SDEP          SDEP_Full     55           77
    10025    SDEP          SDEP_Full     77
    10026    SDEP          SDEP_Full     NULL       77
     

    Kevin, try
    -- code #1 v2 - list
    ;with
    T as (
    SELECT unique_id, b_id, bid_code, super_id,
    max(super_id) over(partition by b_id, bid_code) as super_id2
    from #cred
    where b_id = Left(bid_code, CharIndex('_', bid_code)-1)
    SELECT unique_id, b_id, bid_code, super_id,
    case when super_id=super_id2 then '' else cast(super_id2 as sql_variant) end as [Correct super_id is:]
    from T
    order by unique_id;
    and
    -- code #2 v2 - update
    ;with
    T2 as (
    SELECT unique_id,
    max(super_id) over(partition by b_id, bid_code) as super_id2
    from #cred
    where b_id = Left(bid_code, CharIndex('_', bid_code)-1)
    UPDATE T1
    set T1.super_id= T2.super_id2
    output inserted.unique_id, inserted.b_id, inserted.bid_code,
    deleted.super_id as [old super_id], inserted.super_id as [new super_id]
    from T2 inner join
    #cred as T1 on T1.unique_id=T2.unique_id
    where (T1.super_id <> T2.super_id2) or T1.super_id is null;
    José Diz     Belo Horizonte, MG - Brasil

  • Need help with Update Join Query

    Hello, I am trying to update PID of #child table with PID of #parent table if "lastname & firstname are matches in both table" but my update query is giving some error. Please help and correct the update query. I am also trying to remove any
    blank space from starting and ending.
    drop table #parent,#child
    create table #parent (PID varchar(10), lastname varchar(50), firstname varchar(50))
    insert into #parent values ('100','Josheph','Sumali')
    insert into #parent values ('400','Karen','Hunsa')
    insert into #parent values ('600','Mursan  ','  Terry')
    create table #child (PID varchar(10), lastname varchar(50), firstname varchar(50))
    insert into #child values ('2','Josheph ','Sumali   ')
    insert into #child values ('5','Karen','Kunsi')
    insert into #child values ('6','Mursan ','Terry ')
    Update #child
    set PID = p.PID
    from #child C Join
    #parent p ON c.LTRIM(RTRIM(lastname) = p.LTRIM(RTRIM(lastname)
    AND c.LTRIM(RTRIM(firstname) = p.LTRIM(RTRIM(firstname)
    /* Requested Output */
    PID        lastname      firstname
    100        Josheph       Sumali
    600        Mursan        Terry

    create table #parent (PID varchar(10), lastname varchar(50), firstname varchar(50))
    insert into #parent values ('100','Josheph','Sumali')
    insert into #parent values ('400','Karen','Hunsa')
    insert into #parent values ('600','Mursan ',' Terry')
    create table #child (PID varchar(10), lastname varchar(50), firstname varchar(50))
    insert into #child values ('2','Josheph ','Sumali ')
    insert into #child values ('5','Karen','Kunsi')
    insert into #child values ('6','Mursan ','Terry ')
    Merge #child as t
    Using #parent as p ON (LTRIM(RTRIM(t.lastname)) = LTRIM(RTRIM(p.lastname))
    AND LTRIM(RTRIM(t.firstname)) = LTRIM(RTRIM(p.firstname)) )
    When Matched Then
    Update
    set PID = p.PID;
    update #child
    Set lastname=LTRIM(RTRIM(lastname)), firstname= LTRIM(RTRIM(firstname));
    update #parent
    Set lastname=LTRIM(RTRIM(lastname)), firstname = LTRIM(RTRIM(firstname));
    select * from #child
    select * from #parent
    drop table #parent,#child

  • Help needed with an update query

    Hi,
    I am trying to execute an update query on a table. Here is an example: I have 2 tables t1 and t2 and these tables have 2 similar columns, c11 and c12 in t1 and c21 and c22 in t2. I have to now execute an update statement for the column c11 in t1 with the values for c21 in t2 where the c12 in t1 is equal to c22 in t2. So, the query which I have formulated is:
    update t1 set c11 =
    (select t2.c21 from t1,t2 where t1.c11=t2.c22)
    where t1.c11 in (select t1.c11 from t1);
    But this query gives me an error: ORA-01427: single-row subquery returns more than one row.
    Where am i going wrong? Kindly help.

    Hi,
    CrazyAnie wrote:
    Hi,
    I am trying to execute an update query on a table. Here is an example: I have 2 tables t1 and t2 and these tables have 2 similar columns, c11 and c12 in t1 and c21 and c22 in t2. I have to now execute an update statement for the column c11 in t1 with the values for c21 in t2 where the c12 in t1 is equal to c22 in t2. So, the query which I have formulated is:
    update t1 set c11 =
    (select t2.c21 from t1,t2 where t1.c11=t2.c22)
    where t1.c11 in (select t1.c11 from t1);
    But this query gives me an error: ORA-01427: single-row subquery returns more than one row.
    Where am i going wrong? Kindly help.Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements for all tables) and the results you want from that data.
    In this case, where the problem involves changing t1, the INSERT statements should show reflect the state of the tables before the UPDATE, and the results are shat's in t1 after the UPDATE.
    Without that information, people can only guess at the solution.
    As the error message said, the problem is that the sub-query:
    (select t2.c21 from t1,t2 where t1.c11=t2.c22) is returning more than one row. Each row of t1 can only have one value for c11; which one is it supposed to be?
    It's unusual to have an UDPATE on a table be based on a join of that same table and another table. It's not necessarily wrong, but a more common UPDATE statement is:
    update  t1
    set      c11 = (     select      t2.c21
              from      t2
              where     t1.c12     = t2.c22
    where      t1.c12 in ( select  c22
                  from    t1
                );But again, I don't know where you're starting from (sample data), or where you want to go (results from that data), so it's hard to give you good directions.

  • Help with a update query from a subquery

    Hello All,
    I wanted to see if someone can help me with an update query.
    I need to grab a latitude & longitude from a the same user that is in two accounts. therefore i am trying to update lat/long in a users table for one account based off of the same user in another account. I am matching the users up by phone number and last name. I tried a subquery but am having difficulty.
    I was thinking of something like the following:
    update users
    set lat = getlat, long = getlong
    inner join (select lat as getlat, long as get long from users where account_id = '1')
    on phone = phone and last name = lastname
    where account_id = '2' and lat IS NULL and long IS NULL
    Am I going in the right direction???
    Thanks in advance for any assistance!!!!

    What difficulty are you having? Have you tried what you posted and get an error?
    Although someone may be able to give you sql advice here, I would try posting this over at Stack Overflow as its not really related to Coldfusion.

  • 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.

  • JDBC Sender Update Query

    Does anyone know, in case of Sender JDBC adapter, how is the below handled:
    Say we have the Select Query as below:
    SELECT date FROM TABNAME where FLAG = "TRUE"
    and the update query as below:
    UPDATE TABNAME SET FLAG = "FALSE" where FLAG = "TRUE"
    How do we know whether the adapter will not update the newly added rows (between the times the Select and Update queries were executed) that were not read in the corresponding Select Query.

    Hi,
    We had a similar situation and following description tells you how we handled it:
    1.DB Job was created and scheduled to run at regular intervals which changes the status of the records from FLAG = "TRUE" to an intermediate status, say for e.g. FLAG = "INTM".
    2.Select and update statements were written as follows:
    For e.g.
    SELECT date FROM TABNAME where FLAG = "INTM"
    UPDATE TABNAME SET FLAG = "FALSE" where FLAG = "INTM"
    This solution is running in our Production environment smoothly.
    Question of maintenance of these DB jobs comes into play.But its upto you to decide !!
    Hope it helps !
    Regards,
    Sridhar

Maybe you are looking for

  • Reports hangs: formatting page N....

    Hello, I have form letter report in oracle report 10g. This report has many format triggers and formula columns. The problem is these reports sometimes hang and others not. Any idea??? Thanks!!!! Is urgent. I am desperated.

  • Editing autoexec.bat when setting up j2sdk

    I have grown tired of entering the full location of the Java executables, so I attempted to edit my autoexec.bat as documented on the j2sdk instructions. When I entered my sysedit, the autoexec.bat file had a message stating that that particular file

  • Hyperlink Option in Workflow Notification

    Hi All, I want to put a Hyperlink in Workflow (AR Workflow) notification mail. When the mail will be sent, it should contain the hyperlink of SAP. If enduser will click this hyperlink, it will go to SAP. Regards, Manoj

  • Connecting to Oracle Database - Not Connecting

    I am new to JAVA and for the first time I am trying to connect to an Oracle data using JAVA. Well, I am getting an error when trying to connect to the database. What I can see the error has to do that the strings passed to make the databases connecti

  • Subclips show as masterclips

    hey guys, I have my subclips showing as master clips. I didn't think they should be...but is this because they are subclips from the masterclip? If so, how do I change this info in the browser