Questions tagged [sql-merge]

`SQL MERGE` statement allows us to insert new rows into table and update existing rows depending on given condition. Use this tag in addition to [tag:sql] to make question better categorized.

SQL MERGE statement allows us to insert new rows into table and update existing rows depending on given condition.

Examples of using MERGE statement:

Use this tag in addition to to make question better categorized.

324 questions
0
votes
0 answers

Merge Syntax with NULL Values

Say I want to compare my Source and Target Table using MERGE syntax in SQL I want to update the End_Dt of my target table when target.close_Date is not equal to Source.Close_Date. Table 1 ID Close_Date End_Date 1 NULL 9999-12-31…
itajolosa
  • 1
  • 1
  • 3
0
votes
1 answer

BigQuery : how to make a MERGE operation fail on some conditions?

I want to update a target table (target) according to rows in a source table (source). For that, I use the MERGE statement. However, I would like the whole MERGE operation fails on some conditions, but cannot figure how to do. Example The target…
norbjd
  • 10,166
  • 4
  • 45
  • 80
0
votes
2 answers

convert query from merge to select count in Oracle

I have merge query with below syntax: MERGE INTO target_table USING source_table ON search_condition WHEN NOT MATCHED THEN INSERT (col1,col2,...) values(value1,value2,...) WHERE ; But i want change…
Nitin
  • 71
  • 11
0
votes
1 answer

What am I doing wrong with this MERGE / INSERT query?

I have a database table that I want to update with SQL. Basically, it carries a set of description information for parts of a timetable booklet, but that isn't important. Some of the data is entered already via an application, but it is time…
StuartR143
  • 369
  • 2
  • 10
0
votes
1 answer

Merge not respecting ON in SQL

I have a set of Merge statements I am running in Advantage SQL, but I am finding some aren't working. I know why, but not sure where in my script it's making it go wrong. See the script below. In the ON statement, the part where it says optionaltype…
user8591026
0
votes
1 answer

Merge into table with composite primary key

I'm trying to insert some entries into my table and do nothing when the entry already exists. My primary key consists of more than one column (event_timestamp, device_id, path, message_id). When I try something like following statement in…
ScalaNewbie
  • 173
  • 3
  • 12
0
votes
1 answer

Using Oracle CLOB value inside MERGE

I tried to copy values between tables with this query: MERGE INTO workflow W USING ( SELECT distinct pr.workflow_id, pr.name, pr.description FROM workflow_revision pr, workflow pw WHERE pw.id = pr.workflow_id )WR ON ( W.id =…
Korki Korkig
  • 2,736
  • 9
  • 34
  • 51
0
votes
1 answer

Merge Insert/Update prevent PK violations and deadlocks?

I have stored procedure that handles Insert and Update transactions in one of my tables for now. I'm still testing to see if there is any potential problem with this solution and how I can improve the process. This SP takes few arguments then checks…
espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
0
votes
0 answers

OUTPUT $action in SQL server, casing the updated rows output for a specific column

I am making merge upserts to my data warehouse. I don't need to keep the history on this particular object, so I'm using a type i slowly changing dimension. I'm using OUTPUT $action so I can keep track of how many updates and inserts occurred per…
henhen
  • 23
  • 9
0
votes
2 answers

MERGE INTO Performance

I have a table contains tat contains {service_id, service_name,region_name} As input my procedure gets service_id , i_svc_region list of key,value pairs, which has {service_name, region}. Have to insert into the table if the record does not exists…
Jeevi
  • 2,962
  • 6
  • 39
  • 60
0
votes
0 answers

How to build permissions for logged user?

I have system that has different levels for users depends on what is assigned upon their account was created. So there is four different levels 1,2,3 and 4. First level have full access and then each level below narrows down to data access. So once…
espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
0
votes
0 answers

Does SQL Merge statement require BEGIN TRANS/COMITT TRAN

If a transaction handling is required, how do we do it for below SQL and how do we ROLLBACK MERGE INTO AeoiSdtTemp AS t USING (SELECT statusE, statusF, statusG, statusH, LastModifiedDate, LastModifiedBy, LastReviewedBy, statusI, statusJ, Email,…
Maverick
  • 1,396
  • 5
  • 22
  • 42
0
votes
1 answer

MERGE table from two different schema

I have two same tables from two different schema, db link between schema already created. The table in schema B (old) need to be merged to schema A(new). The table structure between 2 schemas are identical, except an additional timestamp column…
user2102665
  • 429
  • 2
  • 11
  • 26
0
votes
1 answer

Stored procedure INSERT from view into Table based on conditions

My stored procedure calls an API which generates a consumable view of data. I need to insert the records from the generated view into local table. So far, the procedure looks like below. The generated consumable view is [vw_OriginalView_Temp] Local…
Maverick
  • 1,396
  • 5
  • 22
  • 42
0
votes
2 answers

Writing a merge statement in SQL

The process is one where I would get 28 fixed width files and combine it into one table. In the past, this was done via FoxPro. As I have learned today, there were duplicates for which FoxPro did not reject or have any issues with. I have discovered…
Calflamesfann
  • 133
  • 4
  • 16