DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to format and beautify T-SQL code?

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

 


Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE