All Questions
Tagged with sql-server pivot-table
603
questions
0
votes
0
answers
36
views
Convert the rows data into columns by grouping and the column names from row values [duplicate]
My Table code as follows,
CREATE TABLE SalesData (
ID INT,
ProductName VARCHAR(50),
Year INT,
SalesAmount DECIMAL(10, 2)
);
INSERT INTO SalesData (ID, ProductName, Year, SalesAmount)
...
-1
votes
1
answer
64
views
SQL Server transposing rows to columns
I need to transpose rows to columns to display data in different dimensions or meet table format requirements using SQL server.
Starting from this query and this return
SELECT
_p,
_t,
_x,
...
0
votes
1
answer
49
views
SQL Pivot to create 2 columns per row
I have a table that looks like this:
Date
Name
Actual
Target
2023-03-14
Bob
15
15
2023-03-14
Jim
9
5
2023-03-14
Steve
10
9
2023-03-15
Bob
11
11
2023-03-15
Jim
16
16
2023-03-15
Steve
5
12
The ...
-1
votes
1
answer
68
views
Identify SKU id's that have changed status twice in a historical table
I have a historical table which has id, date and status columns. I am trying to identify all the instances where the id's have changed from status 1(Active) to 0(Inactive) and came back to 1(Active ...
0
votes
2
answers
173
views
How to pivot on multiple columns in SQL Server
I have the following table [EMPLOYEE]:
Name
Role
Billed$
Revenue
Joe
Sales Mgr
$500
$600
Joe
VP
$800
$900
Angel
Sales Mgr
$100
$200
Angel
VP
$300
$400
Chad
Sales Mgr
$400
$300
Chad
VP
$600
$100
...
-2
votes
1
answer
121
views
How to Convert Oracle to MS SQL Server - PIVOT and STRING_AGG [closed]
Please help me convert Oracle into SQL Server PIVOT.
The table_cases contains these data:
And the expected result is below. Note: I just short-cut the columns "hour-Nth" for "hour-01&...
1
vote
1
answer
54
views
Group by MIN value in SQL Server pivot table query
I have looked through some similar questions but still can't figure this out.
My query:
SELECT *
FROM
(SELECT
Sites.ID AS SiteID,
MIN(DateInspectionDue) AS DateDue,
...
-4
votes
1
answer
73
views
SQL Server pivot up to 10 columns, if more then automatically fill in the next row [closed]
I have a table with many rows of data
I want it to turn into a table with 10 columns of data
This is a multi-line data table:
SELECT T.*
INTO #Temps
FROM
(SELECT
'A' AS CloGroup, 1 AS ColNumber ...
0
votes
1
answer
59
views
Pivot tabel aggregation - Convert rows to column by date
I'm having difficulty building the syntax. I tried to act as in the examples in a similar thread but I get aggregation errors that I can't deal with.
I will be grateful for any hint in solving my ...
-1
votes
1
answer
176
views
T-SQL change column names in Pivot table
I am trying to rename the column names of this PIVOT. As of right now, the column names are the Ids, I would like to have the Title (instead of the Id) from the GlobalTagging table.
I tried to save ...
0
votes
1
answer
47
views
Get data monthly wise in Sql query from single Column
I need to retrieve monthly wise quantity sold from a table.
How can i fetch all monthly wise data from the same column.
SELECT IH_ITEMNO, SUM(IH_QTY) as July
from tbl_item_history
where IH_DATE LIKE '...
-1
votes
1
answer
141
views
Append a variable to the list of column headers in pivot table
I have the following code for my pivot table:
Create table #CustView
(
Customer_Code VARCHAR(150),
Part_No VARCHAR(150),
Invoice_Date DATETIME,
Quantity ...
1
vote
1
answer
79
views
Why is SQL Server Pivot being case sensitive on TabTypeId instead of treating it as the actual column name?
In T-Sql I am parsing JSON and using PIVOT.
Select * from (select [key],convert(varchar,[value])[value]
from openjson ('{"Name":"tew","TabTypeId":9,"Type":3}'))...
0
votes
1
answer
142
views
Emulate pivot table double click to show detail in SSRS
I have an excel report that basically is a SQL query to get a table of data, then there is another page that shows a pivot table to summarize the data. When I double click a cell in the pivot table, ...
2
votes
3
answers
83
views
Cross tab a Microsoft SQL Server table that has multiple IDs - a 2x2 grid of each variable ID
I have a table in Microsoft SQL Server like the following:
Main_Key
IDx
IDy
IDz
Count
123450
0
0
0
0
123450
0
0
1
1
123450
0
0
2
0
123450
0
0
3
5
123450
1
0
0
4
123450
1
0
1
3
123450
1
0
2
8
...