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
1 answer

SQL Merge (with Temp Table) failing on SubQuery returned more than 1 value (But I am not using a Sub-Query.. in the update)

I am hoping someone can help me out of this tedium...!? As the title suggests I have a Temp Table (create dynamically in a select statement): SELECT * INTO #results FROM Table_1 CROSS APPLY ( SELECT TOP 1 * FROM Table_2 …
CJH
  • 1,266
  • 2
  • 27
  • 61
0
votes
1 answer

SQL Server Merge from local to linked server error

I am trying to merge records from my local database to remote database with insert and update but I'm getting Invalid object name [localdatabase].dbo.MASTER_CORPORATECOMPANY*** error. I have shared the code below. Can anyone tell me how can I…
user2236493
  • 45
  • 1
  • 1
  • 4
0
votes
0 answers

Does merge consider rows in the source table individually or all at once?

I would like to know whether merge: Evaluates each row in the source table separately (i.e. performs the INSERT, UPDATE etc. for that row before moving onto the next row in the source table), or Evaluates all rows in the source table are at the…
JRyan
  • 121
  • 6
0
votes
0 answers

SQL Merge - Number of Colums on Insert Must Match Number of Columns Specified

I am working with a stored procedure where I am using a Merge statement to do an insert or an update based on the conditions. However when trying to compile the procedure I get the error There are more columns in the INSERT statement than values…
Simon Price
  • 3,011
  • 3
  • 34
  • 98
0
votes
1 answer

Table Valued Parameter issue with MONO cs

I have a simple code to create SqlParameter for Table Valued Type. The given code works just fine with .NET 4.0. Issue is with MONO CS (3.12.0), I cannot simply compile the same code in MONO. static SqlParameter GetDataTableParam(string _tableName,…
Ranjan Kumar
  • 497
  • 2
  • 8
  • 24
0
votes
1 answer

mySQL - how to keep count() function from dropping 0 counts?

I'm new to mySQL and working on a query which essentially takes one initial table and summarizes its contents in two separate tables. The second "summary" table is dropping tuples where a value is 0; I need to fix that. Here's the specifics: I…
Pete
  • 1,511
  • 2
  • 26
  • 49
0
votes
1 answer

How do you merge two different SQL Server 2012 database tables in single stored procedure?

MERGE [160.80.3.220].[sample].[dbo].[Products] AS TARGET USING UpdatedProducts AS SOURCE ON (TARGET.ProductID = SOURCE.ProductID) -- When records are matched, update -- the records if there is any change WHEN MATCHED AND TARGET.ProductName <>…
paras
  • 3
  • 2
0
votes
0 answers

updating different data set of the same table without gettig any locks

Hi i have a scenario where 2 different merge statements has to run on the same table on 2 different data sets. the merge or update should happen without any locks. i tried the isolation level 'SERIALIZABLE' but couldn't achieve the results. can…
Maharajaparaman
  • 141
  • 3
  • 12
0
votes
1 answer

Oracle Merge: Update single record in base table using multiple records from source table

I have a merge query as follows: merge into table1 using table2 on (table1.column1 = table2.column1) when mateched then update set column2 = table2.column2; Now it is giving me error like :unable to get a stable set of rows…
Jogesh
  • 9
  • 4
0
votes
1 answer

Oracle sql MERGE INTO with double where clauses

I have the following SQL code (this is how much I made so far): MERGE INTO SCHEMA_1.TABLE_1 table1 USING ( SELECT * FROM SCHEMA_2.TABLE_2 table2 LEFT JOIN SCHEMA_2.VIEW_1 view1 ON table2.COLUMN_4 = view1.COLUMN_1 )t2 ON(table1.COLUMN_2 =…
user3667171
0
votes
2 answers

Not able to merge records in Oracle database using merge statement

SELECT * FROM DIM_TRANS_TYPE WHERE TRANSACTION_TYPE='ILAU'; All I want to accomplish here is change ILAU to IFAU and Instant Loan Authorization Request to Instant Finance Authorization Request in the above-mentioned record. Table Schema: Name …
Nital
  • 5,784
  • 26
  • 103
  • 195
0
votes
0 answers

postgres how to rewrite merge statement using INSERT and UPDATE

I got Merge statement in Oracle (migrating to EDB Postgres), but unfortunately, EDB postgres doesn't support merge statement. So how to rewrite below merge statement using INSERT and UPDATE. BEGIN Merge into sds_dia_error_per_min_data…
0
votes
2 answers

Merge statement for first time insert

I did some research and couldn't find any solution and hence posting it here. We have a dataload job which runs on a daily basis. We have separate DML statements to insert, update etc. We wanted to avoid insert statements to run multiple times. Is…
arvind_cool
  • 293
  • 1
  • 13
0
votes
1 answer

SQL Server deadlock - Fix needed

I'm newbie as a SQL Server DBA , everyday at least once I've got a deadlock issue in SQL Server 2012 server which is using Merge statement. There are no clause like NOLOCK, UPDLOCK, HOLDLOCK has been used in the merge statement. It's a multi user…
0
votes
2 answers

I am trying to write a MS SQL Server Upsert query using MERGE

It works for updating an existing row, but it doesn't insert the row when there's no entry. This is the CREATE TABLE: CREATE TABLE [dbo].[Inventory_Update_Hash_Code] ([Product_Id] [int] NOT NULL, [Feed_Id] [int] NOT NULL, [Hash_Code] [int]…