I found an easy, web-based tool that allows me to consistently reformat SQL code here. I have no affiliation with the producers of this tool, except that I’ve used this tool fairly frequently over the past almost year. I’ve used integrated tools
It is fairly common when building a Business Intelligence applications to need to analyze "legacy" code from multiple systems. It is likely that the code in the source systems was composed by multiple developers with differing coding styles. This is not an issue unique to BI, but it’s especially noticable because we are likely sourcing from mutiple environments.
To put my "money where my mouth is" so to speak, here’s how I like to reformat SQL code.
Before formatting:
SELECT FactInternetSales.OrderQuantity, FactInternetSales.UnitPrice, FactInternetSales.SalesAmount, DimProduct.EnglishProductName,
DimProductCategory.EnglishProductCategoryName, DimProductSubcategory.EnglishProductSubcategoryName, DimPromotion.EnglishPromotionName,
DimSalesTerritory.SalesTerritoryRegion, DimSalesTerritory.SalesTerritoryCountry, DimSalesTerritory.SalesTerritoryGroup,
DimOrderDate.FullDateAlternateKey AS OrderDate, DimDueDate.FullDateAlternateKey AS DueDate, DimShipDate.FullDateAlternateKey AS ShipDate
FROM FactInternetSales INNER JOIN
DimCustomer ON FactInternetSales.CustomerKey = DimCustomer.CustomerKey INNER JOIN
DimProduct ON FactInternetSales.ProductKey = DimProduct.ProductKey INNER JOIN
DimProductSubcategory ON DimProduct.ProductSubcategoryKey = DimProductSubcategory.ProductSubcategoryKey INNER JOIN
DimProductCategory ON DimProductSubcategory.ProductCategoryKey = DimProductCategory.ProductCategoryKey INNER JOIN
DimPromotion ON FactInternetSales.PromotionKey = DimPromotion.PromotionKey INNER JOIN
DimSalesTerritory ON FactInternetSales.SalesTerritoryKey = DimSalesTerritory.SalesTerritoryKey INNER JOIN
DimTime AS DimOrderDate ON FactInternetSales.OrderDateKey = DimOrderDate.TimeKey INNER JOIN
DimTime AS DimShipDate ON FactInternetSales.ShipDateKey = DimShipDate.TimeKey INNER JOIN
DimTime AS DimDueDate ON FactInternetSales.DueDateKey = DimDueDate.TimeKey
WHERE (MONTH(DimOrderDate.FullDateAlternateKey) = 7) AND (MONTH(DimShipDate.FullDateAlternateKey) = 8) AND
(DimSalesTerritory.SalesTerritoryCountry <> N’United States’)
After formatting:
SELECT
FactInternetSales.OrderQuantity
, FactInternetSales.UnitPrice
, FactInternetSales.SalesAmount
, DimProduct.EnglishProductName
, DimProductCategory.EnglishProductCategoryName
, DimProductSubcategory.EnglishProductSubcategoryName
, DimPromotion.EnglishPromotionName
, DimSalesTerritory.SalesTerritoryRegion
, DimSalesTerritory.SalesTerritoryCountry
, DimSalesTerritory.SalesTerritoryGroup
, DimOrderDate.FullDateAlternateKey AS OrderDate
, DimDueDate.FullDateAlternateKey AS DueDate
, DimShipDate.FullDateAlternateKey AS ShipDate
FROM FactInternetSales
INNER JOIN DimCustomer
ON FactInternetSales.CustomerKey = DimCustomer.CustomerKey
INNER JOIN DimProduct
ON FactInternetSales.ProductKey = DimProduct.ProductKey
INNER JOIN DimProductSubcategory
ON DimProduct.ProductSubcategoryKey = DimProductSubcategory.ProductSubcategoryKey
INNER JOIN DimProductCategory
ON DimProductSubcategory.ProductCategoryKey = DimProductCategory.ProductCategoryKey
INNER JOIN DimPromotion
ON FactInternetSales.PromotionKey = DimPromotion.PromotionKey
INNER JOIN DimSalesTerritory
ON FactInternetSales.SalesTerritoryKey = DimSalesTerritory.SalesTerritoryKey
INNER JOIN DimTime AS DimOrderDate
ON FactInternetSales.OrderDateKey = DimOrderDate.TimeKey
INNER JOIN DimTime AS DimShipDate
ON FactInternetSales.ShipDateKey = DimShipDate.TimeKey
INNER JOIN DimTime AS DimDueDate
ON FactInternetSales.DueDateKey = DimDueDate.TimeKey
WHERE
(MONTH(DimOrderDate.FullDateAlternateKey) = 7)
AND
(MONTH(DimShipDate.FullDateAlternateKey) = 8)
AND
(DimSalesTerritory.SalesTerritoryCountry <> N’United States’)