|
SQL Format formats an beautifies T-SQL source code. In the input window you paste the T-SQL code like following:
USE AdventureWorks;
GO
WITH cteVendorPO
AS
(
SELECT PurchaseOrderID,
Employee=FirstName+' '+LastName,
Vendor = v.Name
FROM Purchasing.PurchaseOrderHeader poh
JOIN HumanResources.Employee e
ON poh.EmployeeID = e.EmployeeID
JOIN Person.Contact c
ON e.ContactID = c.ContactID
JOIN Purchasing.Vendor v
ON v.VendorID = poh.VendorID
)
SELECT *
FROM cteVendorPO v
PIVOT
(
COUNT (PurchaseOrderID)
FOR Employee IN
( [Erin Hagens], [Linda Meisner], [Sheela Word], [Frank Pellow], [Reinout Hillmann] )
) AS pvt
ORDER BY pvt.Vendor
In the result window it is returned formatted and beautified. This is how it looks after copy and paste to Management Studio Query Editor:
USE AdventureWorks;
GO
WITH cteVendorPO
AS (SELECT PurchaseOrderID,
Employee = FirstName + ' ' + LastName,
Vendor = v.Name
FROM Purchasing.PurchaseOrderHeader poh
JOIN HumanResources.Employee e
ON poh.EmployeeID = e.EmployeeID
JOIN Person.Contact c
ON e.ContactID = c.ContactID
JOIN Purchasing.Vendor v
ON v.VendorID = poh.VendorID)
SELECT *
FROM cteVendorPO v
PIVOT
(Count(PurchaseOrderID)
FOR Employee IN ( [Erin Hagens],[Linda Meisner],[Sheela Word],[Frank Pellow],[Reinout Hillmann] ) ) AS pvt
ORDER BY pvt.Vendor
Click Here to Link to SQL Format
|