Solved

UPDATE SQL with FROM and JOIN Statements

Posted on 2011-03-08
5
878 Views
Last Modified: 2012-05-11
Hi Experts

The SQL Below is from SQL SErver. Following that is my attempt at an Oracle equivalent - but it is not working

      UPDATE AQD.qa_CheckList_Item SET Column1 = Standard_Item_GUID
      FROM AQD.qa_CheckList_Item CI
      INNER JOIN AQD.qa_StandardItem SI ON CI.column1 = SI.Standard_Item_ID
      INNER JOIN AQD.qa_Checklist_Properties CP ON CI.CheckList_Code = CP.CheckList_Code
      WHERE (CP.ColumnID = 1)
        AND (ISNUMERIC(CI.Column1) = 1)    -- Identities only
        AND (CP.Source IS NOT NULL)        -- we have a Standard
        AND (SI.[Standard] = CP.Source)    -- Standard must match

And in Oracle

UPDATE QA_CHECKLIST_ITEM
SET QA_CHECKLIST_ITEM.COLUMN1 = (SELECT DISTINCT CAST(sys.utl_raw.Cast_To_Varchar2(Standard_Item_GUID) AS Varchar2(38))
FROM AQD.QA_STANDARDITEM_SOURCE SI
INNER JOIN AQD.QA_CHECKLIST_ITEM CI ON CI.COLUMN1 = SI.STANDARD_ITEM_ID
INNER JOIN AQD.QA_CHECKLIST_PROPERTIES CP ON CI.CHECKLIST_CODE = CP.CHECKLIST_CODE
WHERE (CP.COLUMNID = 1)
  AND LENGTH(TRIM(TRANSLATE(CI.COLUMN1,' +.01234656789',' ')))IS NULL
  AND CP.SOURCE IS NOT NULL
  AND SI.STANDARD = CP.SOURCE
  AND rownum = 1);
0
Comment
Question by:Kelvin Sparks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:choukssa
ID: 35076628
The oracle update statement you have posted is a statement with update value derived from a sql statement. If the sql returns a value the update should work fine.

Do you want to convert this update statement into one with where clause?

--choulssa
0
 
LVL 2

Assisted Solution

by:choukssa
choukssa earned 250 total points
ID: 35076816
One way of doing this

update qa_checklist_item qci
set    qci.column1 =
(
    select  distinct cast(sys.utl_raw.cast_to_varchar2(standard_item_guid) as varchar2(38))                
    from     aqd.qa_standarditem_source si,             
             aqd.qa_checklist_properties cp
    where    qci.column1 = si.standard_item_id
    and      qci.checklist_code = cp.checklist_code        
    and      cp.columnid = 1                        
    and      length(trim(translate(qci.column1,' +.01234656789',' '))) is null
    and      cp.source    is not null
    and      si.standard  = cp.source
    and      rownum       = 1
)
where  exists
(
    select   1
    from     aqd.qa_standarditem_source si, 
             aqd.qa_checklist_properties cp
    where    qci.column1 = si.standard_item_id
    and      qci.checklist_code = cp.checklist_code        
    and      cp.columnid = 1                        
    and      length(trim(translate(qci.column1,' +.01234656789',' '))) is null
    and      cp.source    is not null
    and      si.standard  = cp.source
    and      rownum       = 1
)

Open in new window



--choukssa
0
 
LVL 4

Accepted Solution

by:
pinkuray earned 250 total points
ID: 35077412
there are few tools in market which will do the query conversion like SWISS SQL.

0
 
LVL 22

Author Comment

by:Kelvin Sparks
ID: 35088410
Thanks fiolks for the pointers. Managed to use a conversion tool which gave me close to the following. After some editing and playing around the following works. Appreciate the help, so points shared

MERGE INTO qa_CheckList_Item CI
USING (SELECT CI.ROWID row_id,  SI.STANDARD_ITEM_GUID
FROM qa_CheckList_Item CI
       JOIN qa_standarditem_source SI
        ON CI.column1 = SI.Standard_Item_ID
       JOIN qa_Checklist_Properties CP
        ON CI.CheckList_Code = CP.CheckList_Code
WHERE ( CP.ColumnID = 1 )
  AND ( sqlserver_utilities.isnumeric(CI.Column1) = 1
 )
  AND ( CP.Source IS NOT NULL
 )
  AND ( SI.STANDARD = CP.Source
 )) src
ON ( CI.ROWID = src.row_id )
WHEN MATCHED THEN UPDATE SET Column1 =  CAST(sys.utl_raw.Cast_To_Varchar2(STANDARD_ITEM_GUID) AS Varchar2(38));

Kelvin
0
 
LVL 22

Author Closing Comment

by:Kelvin Sparks
ID: 35088421
Appreciate the help
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question