I have the following script and would like to change it so that it agrees with the international standards. I use SQL-Server but whenever possible I’d like to follow the international standards for SQL. I don’t believe that the square brackets are standard – should I replace them with double quotes?
Without paying to get a copy of the standards document are there any resources on the internet which give examples of scripts formatted and laid out exactly as required by the standards?
SELECT
a.UserAccountKey,
SUM(ISNULL(b.[measure Y],0.0)) AS "measure Y",
SUM(ISNULL(c.[measure Z],0.0)) AS "measure Z"
FROM
XXX a
LEFT OUTER JOIN YYYY b ON
a.UserAccountKey = b.UserAccountKey
LEFT OUTER JOIN ZZZZ c ON
a.UserAccountKey = c.UserAccountKey
GROUP BY
a.UserAccountKey
EDIT
My only slight preference that is not classic standard is the following. This was put forward by AaronBertrand and I agree that it’s more readable – especially if the SELECT clause has 20 or 30 fields:
SELECT
a.UserAccountKey,
"measure Y" = SUM(ISNULL(b."measure Y",0.0)),
"measure Z" = SUM(ISNULL(c."measure Z",0.0)),
"measure longertitle" = SUM(ISNULL(c."measure longertitle",0.0)),
"me short" = SUM(ISNULL(c."me short",0.0))
FROM
Change
ISNULLtoCOALESCEand square brackets to"and then it validates.This does mean that you need to ensure that
QUOTED_IDENTIFIERisONin SQL Server.