Sql Server 2019 Compatibility

      No Comments on Sql Server 2019 Compatibility

COMPUT Clause is not allowed in Database Compatibility 110

Issue Details-


Impact- The COMPUTE clause generates totals that appear as additional summary columns at the end of the result set. However, this clause is no longer supported in SQL Server 2012.

The COMPUTE clause generates totals that appear as additional summary columns at the end of the result set. However, this clause is no longer supported in SQL Server 2012.

The ROLLUP is an extension of the GROUP BY clause. The ROLLUP option allows you to include extra rows that represent the subtotals, which are commonly referred to as super-aggregate rows, along with the grand total row. By using the ROLLUP option, you can use a single query to generate multiple grouping sets.

Recommendation-

The T-SQL module needs to be re-written using the ROLLUP operator instead.
The code below demonstrates how COMPUTE can be replaced with ROLLUP.

COMPUTE-

SELECT SalesOrderID, UnitPrice, UnitPriceDiscount
FROM Sales.SalesOrderDetail
ORDER BY SalesOrderID
COMPUTE SUM(UnitPrice), SUM(UnitPriceDiscount) BY SalesOrderID

WITH ROLLUP-

SELECT SalesOrderID, UnitPrice, UnitPriceDiscount,SUM(UnitPrice) as UnitPrice , SUM(UnitPriceDiscount) as UnitPriceDiscount
FROM Sales.SalesOrderDetail
GROUP BY SalesOrderID, UnitPrice, UnitPriceDiscount
WITH ROLLUP

EXAMPLE-OUTPUT COMPUTE-

SELECT Country, [State], City, [Population (in Millions)] FROM Population
ORDER BY Country, [State], City
COMPUTE SUM([Population (in Millions)]) BY Country,[State]
COMPUTE SUM([Population (in Millions)])

Eaxmple Output After Update WITH ROOLUP-

SELECT Country,[State],City,
    SUM ([Population (in Millions)]) AS [Population (in Millions)] FROM Population
    GROUP BY Country,[State],City
WITH ROLLUP

Leave a Reply

Your email address will not be published. Required fields are marked *