Note that there are some explanatory texts on larger screens.

plurals
  1. POcan i pivot this entire query to return different results?
    primarykey
    data
    text
    <p>This query is returning exactly what i need but im trying to create a pivot table out of it as well. I want to be able to SUM the column defined as SLAStatus in the CASE clause (dont know if thats even possible) as well as count the OrderID column as well as calculate(sum of SLAStatus column)/(Count of OrderID Column) to return a percentage of orders withing SLA. Been looking online everywhere but cant seem to figure this out</p> <pre><code>SELECT oi.OrderID, o.Address1 as StreetAddress, c.Name as County, o.State, p.Abbreviation, oi.OrderDate as Dateentered, DATEADD(dd, DATEDIFF(dd, 0, oi.DeliveredDate), 0) as DateCompleted, DATEADD(dd, DATEDIFF(dd, 0, oi.RequiredByDate), 0) as EstimatedDeliveryDate, CASE WHEN oi.DeliveredDate &lt;= oi.RequiredByDate THEN '1' ELSE '0' END AS SLAStatus, cl.Name as Client, clb.Name as Client2, v.ContactFirstName + ' ' + v.ContactLastName as Appraiser FROM OrderItems oi JOIN Orders o on o.OrderID = oi.OrderID JOIN Counties c on c.FIPS = o.FIPS JOIN Products p on p.ProductID = oi.ProductID JOIN Clients cl on cl.ClientID = o.ClientID JOIN ClientBranches clb on clb.ClientID = cl.ClientID JOIN Vendors v on v.VendorID = oi.VendorID JOIN Milestones m on m.MilestoneID = oi.LastMilestoneID WHERE cl.Name not like '%TEST%' and '2012-03-01' &lt;= (select MAX(MilestoneDate) from OrderItemMilestones where OrderID = oi.OrderID and OrderItemID = oi.OrderItemID and MilestoneID in (100,130,140,150)) and '2012-04-10' &gt;= (select MAX(MilestoneDate) from OrderItemMilestones where OrderID = oi.OrderID and OrderItemID = oi.OrderItemID and MilestoneID in (100,130,140,150)) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload