Tag: pivot

splitting one column into several

First time poster here, so please forgive mishaps. I have a query in sql that for the sake of simplicity returns duration, business duration and impacted service. The problem lies in the fact that if its impacted service, sometimes it has more than one value in the row. For example it can be ‘crm, payrol […]

Pivot table how to not allow nulls in multiple columns

I want to put a condition if [2015] and [2016] are NULL then hide row, but I cant pull it off. I don’t have interest in the billname if it doesn’t have data. SELECT IssuedByUserGroup, BILLNAME, SUM([2016]) AS [2016], SUM([2015])AS [2015] FROM Sum_Orders PIVOT ( SUM(Sum_SellPrice) FOR OrderperiodYear IN ([2016],[2015]) ) AS pvt WHERE ( […]

How do I sort a SQL Server 2008 pivot result columns and rows?

I’m using This to get pivot results for a table. But I want the resulting columns and rows both in a specific order. So the rows would be sorted by CDATE and the columns would be CDATE, BALANCE, then the DATE columns. CDATE | BALANCE | 04-2007 | 05-2007 | 06-2007 | TRANS TOT 2003-01-15 […]

split a string in a column and pivot in sql

I am using sql server 2014 and I have a table like this (##tt_allresults) ID | Area | Event | 1 | FB1 | Dev_Chg, Old Value: 0, New Value: 50, Workstation: Blah1, Function: Blah1 func | 1 | FB2 | Dev_Chg, Old Value: 99, New Value: 5, Workstation: Blah2, Function: Blah2 func | 1 […]

dynamic pivot issue in sql server 2012

I’m trying to implement a dynamic pivoting in SQL to represent my results given below ID Charge Message Amt Of Billing 4563 WEB FEE 9.75 4563 MONTHLY FEE 6 4563 CLUB FEE 9.95 4648 MONTHLY FEE 6 4648 ACCOUNT FEE 5 4648 CLUB FEE 9.95 4648 WEB FEE 9.75 4650 MONTHLY FEE 6 4650 WEB […]

Yet another SQL Pivot

Quick question about pivoting. I have the following data: c1 | c2 | c3 | c4 | c5 pk1 | r12 | r13 | r14 | r15 pk2 | r22 | r23 | r24 | r25 pk3 | r32 | r33 | r34 | r35 I would like to rotate it as follow [c1] | […]

SQL Pivot possible for this data set?

I trying to write a query and I need some help. I have some data that looks like this: However, the end users would like a Pivot so that the data displays like this: I wrote this code: SELECT * FROM ( SELECT TOP 100 Log0.sn ,CONVERT(VARCHAR(50), Log0.capture_time) AS Instant ,CONVERT(VARCHAR(50),Log0.address) + ‘/’ + Log0.[Key] […]

SQL Server 2008, pivot with no aggregate fuction

I have a database table that looks like this: product||installed/removed||date A|| 1||Jan 1, 2016 A|| 0||Mar 16, 2016 A|| 1||May 15, 2016 B|| 1||Feb 3, 2016 C|| 0||Nov 15, 2015 D|| 1||Dec 4, 2015 installed/removed is a flag which means 1 = installed, 0 =removed. I want to make it look like this: Product|| 1|| […]

SQL results grouped by Weeks, Day

I have a table like below: Date ServingTime MeasuredValue —————————————- 01-11-16 Breakfast 45 01-11-16 Lunch 50 01-11-16 Dinner 60 02-11-16 Breakfast 23 02-11-16 Lunch 45 02-11-16 Dinner 83 … … 30-11-16 Breakfast 56 30-11-16 Lunch 16 30-11-16 Dinner 34 And Query like below: DECLARE @DatePeriod date = ‘2016-11-30’ SELECT ServingTime, ISNULL([1], 0) AS ‘Week 1’, […]

How to perform Sql pivot without aggregation and with order by?

I have Persons table As shown in image and i want to convert it into Table2 Table Image This is how I am Trying to build query in Sql Server but i don’t know what to write in place of aggregate function and one more thing is that I want all person name in alphabetical […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.