I’ve looked at some answers but none of them seem to be applicable to me. Basically I have this result set: I just want to convert this to I know I should probably use PIVOT. But the syntax is just not clear to me. The order numbers are always two. To make things clearer Answer And if you want to
Tag: sql-server
SQL Server Transpose FieldValue as FieldName
SQL Server Transpose , FieldValues as FieldNames: Hello All, I have a tricky request for all of you. I have a table with the following data Field1 Field2 Field3 Field4 ——-…
Problem with field not equal to null in case statement
So I have EXISTS in huge query which looks like this: EXISTS( SELECT * FROM ExistTable WHERE ExTableFieldA = @SomeGuid AND ExTableFieldB = MainTableFieldB AND …
MS SQL Server Update or Clear based on matching values
I need some help in a scenario that I am working on. I have two tables Product_Staging and Product. The contents of the table are below. Product_Staging: Account_No Product_No …
Dynamically selection of Column Name
I want to select Column Name which has non null and non zero value. So any column name which has 0 or NULL should not be displayed in the output grid I have the Source table as below I want to group by Col1 and Display Col1, MIN(Col2), MIN(Col3), MIN(Col4) and ColRes as (Name of the column with value more
How to use a table variable within EXECUTE command?
I have this code: DECLARE @mytable TABLE (x INT); EXECUTE (‘SELECT * FROM ‘ + @mytable); When I run the code, I get this error: Must declare the scalar variable “@mytable “. I know that @mytable …
Find the most popular month for customers to order a certain product
I am trying to find out which month has the most orders for a certain product (Product HHYDP). This is my code so far, but each time I try to use GROUP BY and SORT BY functions related to my problem, …
Writing data to a single row of multiple tables
I have a table with error numbers and a reference for storing errors. I need to write errors in one line, I got the following option, but it depends on the order of records in the table. DECLARE @…
Cannot exclude previous non-duplicate rows
In a nutshell, here it is: I have 1000(ish) employees who have multiple recurrent annual training requirements I need to be able to sort the employees by County, Facility, Employee, and Type of Training (and also allow for sorted lists at each level) I want to display only the most recent date the Employee to…
Joining to return all rows even when there are no results
I’m trying to get a list how many products we’ve sold, per company, by all categories. I’d like the results to look like: Category A Company 1 0 Category A Company 2 0 Category A Company 3 …