Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:42:57+00:00 2026-06-16T04:42:57+00:00

How to update row if exist A,B,Tarih and Not exist how to insert? My

  • 0

How to update row if exist A,B,Tarih and Not exist how to insert?

My original Code:

 Insert X(A,B,C,D,E,Tarih)
select substring(dosya,2,25) as A, 
substring(dosya,27,15) as B,
substring(dosya,70,40) as C,
CONVERT(DECIMAL(17,2),substring(dosya,52,17)) as D,
case when substring(dosya,124,2)='00' then 'TL'
     when substring(dosya,124,2)='01' then 'USD'
     when substring(dosya,124,2)='02' then 'CHF'
     when substring(dosya,124,2)='03' then 'CAD'
     when substring(dosya,124,2)='04' then 'KWD'

     when substring(dosya,124,2)='05' then 'GBP'
     when substring(dosya,124,2)='06' then 'SAR'
     when substring(dosya,124,2)='07' then 'JPY'
     when substring(dosya,124,2)='08' then 'EUR'

     when substring(dosya,124,2)='09' then 'AUD'
     when substring(dosya,124,2)='10' then 'IRR'
     when substring(dosya,124,2)='11' then 'DK'
     when substring(dosya,124,2)='12' then 'SEK'
 else 'Döviz' end  as E,
@tarih as Tarih
 from #TempLog

i want to update existing value

Pseudo code :

if exist ( A,B,C in BankaEntegrasyonLog)

{

       Update Row!

}

else

{

 Insert 

X(A,B,C,D,E,Tarih)

select substring(dosya,2,25) as   . . . . .  

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:42:59+00:00Added an answer on June 16, 2026 at 4:42 am

    You’ll want to use the MERGE statement.

    First, let’s create a test table:

    CREATE TABLE TestLog( SomeKey INTEGER, SomeAttribute VARCHAR(80));
    

    And we can insert some values into it:

    INSERT INTO TestLog( SomeKey, SomeAttribute ) VALUES ( 43, 'Something' );
    INSERT INTO TestLog( SomeKey, SomeAttribute ) VALUES ( 55, 'Another' );
    INSERT INTO TestLog( SomeKey, SomeAttribute ) VALUES ( 77, 'Demo' );
    

    Now, let’s use MERGE with a key that already exists. If we should update ‘Something’ to ‘updated!’ for SomeKey = 43:

    MERGE TestLog AS TARGET
    USING (SELECT 43 AS SomeKey, 'Updated!' AS SomeAttribute)
    AS SOURCE( SomeKey, SomeAttribute )
    ON (TARGET.SomeKey = SOURCE.SomeKey )
    WHEN MATCHED THEN
       UPDATE SET SomeAttribute = Source.SomeAttribute
    WHEN NOT MATCHED THEN
       INSERT (SomeKey, SomeAttribute)
       VALUES (SOURCE.SomeKey, SOURCE.SomeAttribute);
    

    We can check that it worked:

    SELECT * FROM TestLog WHERE SomeKey = 43;

    and we indeed see “Updated!” for SomeAttribute. We can try a new value:

    MERGE TestLog AS TARGET
    USING (SELECT 22 AS SomeKey, 'Newone!' AS SomeAttribute)
    AS SOURCE( SomeKey, SomeAttribute )
    ON (TARGET.SomeKey = SOURCE.SomeKey )
    WHEN MATCHED THEN
       UPDATE SET SomeAttribute = Source.SomeAttribute
    WHEN NOT MATCHED THEN
       INSERT (SomeKey, SomeAttribute)
       VALUES (SOURCE.SomeKey, SOURCE.SomeAttribute);
    

    And to check it:

    SELECT * FROM TestLog;
    

    We indeed see a new fourth row with (22, ‘Newone!’). It shouldn’t be hard to expand this example to your specific table and insert pattern. Let me know if you need more help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I asked does https://stackoverflow.com/questions/11144014/does-mysql-update-add-a-row-if-it-doesnt-exist and I was told that I'm using columns incorrectly.
I'm trying to update a row in my database but it's not running. Below
I'm trying to do a single row insert/update on a table but all the
I am looking for a way to only insert when the row does not
The following code is straight from the docs and should insert a row into
I am doing an update to a table for a row that may not
i'm trying to update my code with values that already exist there(in the same
I want to Insert a new row into my table if it does not
Possible Duplicate: Solutions for INSERT OR UPDATE on SQL Server Only inserting a row
I want to update or insert a row in a table. I have also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.