What are the challenges you face when working across database platforms? Take the survey
Options

CAST columnname with square brackets and no space after AS

Hi,

I found an error in SQL Server Prompt when CAST is used with a column name in square brackets and no space between the final bracket and the AS keyword. Though the query is valid according to SQL Server's DBE, SQL Prompt fails when the brackets are removed.

Query:

SELECT Name
      ,SUM(CAST([NumberOfProducts]AS bigint))                AS NumberOfProducts
      ,SUM(CAST([NumberOfItems]AS bigint))                   AS NumberOfItems
FROM
   ( VALUES ( 'Item1', 12, 22 )
          , ( 'Item2', 14, 25 ) ) AS orders( Name, NumberOfProducts, NumberOfItems )
GROUP BY Name

Result:
SELECT orders.Name
      ,SUM(CAST(orders.NumberOfProductsAS bigint))                AS NumberOfProducts
      ,SUM(CAST(orders.NumberOfItemsAS bigint))                   AS NumberOfItems
FROM
   ( VALUES ( 'Item1', 12, 22 )
          , ( 'Item2', 14, 25 ) ) AS orders( Name, NumberOfProducts, NumberOfItems )
GROUP BY orders.Name

Error: 'Incorrect syntax near bigint'

Will this be fixed?

Regards,
Arno

Best Answer

Answers

Sign In or Register to comment.