Search code examples
sqlsql-servermigrationcompatibility

Behavior Changes on SELECT


I'm migrating a SQL Server 2008 database to SQL Server 2019, I have used Microsoft Data Migration Assistant, to look for search any behavior changes, issues or syntax errors.

I have a SELECT that gives me compatibility errors to do the migration:

Object uses the old style join syntax which can have poor performance at database compatibility level 90 and higher.

This is my SELECT that I think makes the error:

SELECT 
    @Pro = CEILING((BaseDev * 100) / (ISNULL(BaseExe, 0) + ISNULL(BaseDev, 0)))
FROM 
    (SELECT SUM(Base) 'BaseDev'
     FROM Table1
     WHERE Con = @Con AND Lib <> 0 AND Tip = 1 
       AND Fac = 'V' AND ISNULL(Pct, 0) <> 0) A,
    (SELECT SUM(Base) 'BaseExe'
     FROM Table1
     WHERE Con = @Con AND Lib <> 0 AND Tip = 1 AND Fac = 'V' 
       AND ISNULL(Pct, 0) = 0) B

Solution

  •   SELECT @Pro = CEILING((A.BaseDev * 100) / (ISNULL(B.BaseExe, 0) + ISNULL(A.BaseDev, 0)))
       FROM 
       (
           SELECT SUM(Base) AS BaseDev
            FROM Table1
            WHERE Con = @Con AND Lib <> 0 AND Tip = 1 AND Fac = 'V' AND ISNULL(Pct, 0) <> 0
       ) A
      CROSS JOIN 
       (
           SELECT SUM(Base) AS BaseExe
           FROM Table1
           WHERE Con = @Con AND Lib <> 0 AND Tip = 1 AND Fac = 'V' AND ISNULL(Pct, 0) = 0
       ) B
    

    I guess you can replace your query with this one