Merge not inserting new values

I’m trying to use MERGE to insert new values to a table only if they don’t already exists in the same table. This is the query I am using: MERGE [dbo].[TARGET_TABLE] AS Target USING (SELECT [NAME] …

Need to match a field with another that has commas on it’ s value

I would like to match the field values of “FORMULATION” from TABLE 1 to “C_TEST_ARTICLE” from table 2, that has mutiple of these formulation sepparated by commas. Table 1: +——–…

Arithmetic overflow error converting nvarchar to data type numeric in case query

I am trying to show the number of quotes won as a percentage of the total number of quotes in a time frame. For example. I have a total of 294 quotes and 173 of them are won. The result I am looking …

SQL Pivot and get column row data

I have tables and data as below. Trying to get the Manufacturer and the questions they answered by joining and pivot but able to. Added the expected output at the end but no luck. Any suggestions are …

Is there a way of getting a proportional section of an SQL table?

I’m trying to split a single query into 4 parts, for readability purposes. Having it as a single query, while adequate, isn’t “pretty” for display purposes. An example would be a query that …

How to loop through JSON array to insert rows in SQL Table using TSQL?

I have following query where I would like to insert data from JSON: INSERT INTO EncExt ( reference ,system ,code ,display ) SELECT JSON_VALUE(record, ‘$.id’) AS reference , JSON_VALUE(…

Delete rows from 2 tables using a single query

I have the following database-schema: I have the following example data: CREATE TABLE computermapping ( ComputerMappingID int NOT NULL, PrinterGUID char(36) NOT NULL, ComputerGUID char(36) NOT …

Determining cause of query timing out

I have a query that I’ve spent some time optimizing, it will normally run in less than a second. Occasionally, though, it will take a minute or two to run which causes the calling application to throw …

How can I create summaries across columns?

I have an existing application database table supporting an application, and I’ve been tasked with adding another feature. Currently, we have a build table that stores information about product builds….

Create date table of every second between two dates

I need to create a table of every second between two input dates eg between 01/01/2015 00:00:01 and 05/01/2016 00:00:00 So a 3m row expected output that looks like this: Does this need a CLR? …