Update statement

Vineet S 910 Reputation points
2024-09-21T20:07:21.3333333+00:00

How to convert query into update statement... Unable to do it

select rt.outstandingamount,rt.outstandingamount * TT_USD.RateMultiplier,ENTITY,FromCurrencyKeyFK,ConversionCurrencyKey,RateMultiplier

from deltalake.FactARReceiptDetail RT LEFT outer JOIN DeltaLake.DimCurrencyCode cur1 ON CASE WHEN TRIM(RT.currency) IN ('B-USD', 'Z-US$') THEN 'USD'

                                      WHEN TRIM(RT.currency) IN ('B-CAD', 'Z-C$') THEN 'CAD'

                                      WHEN TRIM(RT.currency) IN ('Z-CNY') THEN 'CNY' ELSE TRIM(RT.currency) END = cur1.CurrencyCode AND cur1.DeltaActive = TRUE

                                      LEFT OUTER JOIN DimTempCurrency TT_USD ON TT_USD.FromCurrencyKeyFK = trim(cur1.ConversionCurrencyKey)
```---left join DimTempCurrency b on a.currency=where InvoiceNumber = 'INV250430' 

where cur1.CurrencyKey='19' and ENTITY like '%RE%'--and  outstandingamount <>0 and invoicenumber='INVE049206'

and   RT.outstandingamount IS NOT NULL

   AND RT.outstandingamount <> '0'
Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,770 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
{count} votes

Accepted answer
  1. LiHongMSFT-4306 27,016 Reputation points
    2024-09-23T02:12:11.8666667+00:00

    Hi @Vineet S

    How to convert query into update statement... Unable to do it

    Here is the syntax of the UPDATE with JOIN clause:

    UPDATE 
        t1
    SET 
        t1.c1 = t2.c2,
        t1.c2 = expression,
        ...   
    FROM 
        t1 [INNER | LEFT] JOIN t2 ON join_predicate
    WHERE 
        where_predicate;
    

    For better support, you could post the code you wrote or the error you encountered.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 111.1K Reputation points
    2024-09-21T20:29:42.0166667+00:00

    Maybe this?

    UPDATE rt 
    SET    rt.outstandingamount = 99
    from deltalake.FactARReceiptDetail RT 
    LEFT outer JOIN DeltaLake.DimCurrencyCode cur1 ON CASE WHEN TRIM(RT.currency) IN ('B-USD', 'Z-US$') THEN 'USD'
                                          WHEN TRIM(RT.currency) IN ('B-CAD', 'Z-C$') THEN 'CAD'
                                          WHEN TRIM(RT.currency) IN ('Z-CNY') THEN 'CNY' ELSE TRIM(RT.currency) END = cur1.CurrencyCode AND cur1.DeltaActive = TRUE
                                          LEFT OUTER JOIN DimTempCurrency TT_USD ON TT_USD.FromCurrencyKeyFK = trim(cur1.ConversionCurrencyKey)
    where cur1.CurrencyKey='19' and ENTITY like '%RE%'--and outstandingamount <>0 and invoicenumber='INVE049206'
    and RT.outstandingamount IS NOT NULL
    AND RT.outstandingamount <> '0'
    

    In all seriousness, I don't know what you want to achieve in your UPDATE statement, so I had to consult my crystal ball.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.