Hi Guys,
We're upgrading our SQL Server database from 2005 to 2012.
I ran the Upgrade Advisory report and got this issue "Non-integer constants are not allowed in the ORDER BY clause in 90" because of the script below
SELECT gp.BRAND+' <> '+gp.CATEGORY AS 'full name', gp.PRODCODE, gp.CATEGORY FROM dbo.GFK_PRODUCT gp ORDER BY 'full name'
I tried running the same query in our test SQL Server 2012 and it ran successfully.
Now I'm confuse if i still need to change it
I google the issue a bit and came across this link and mentioned this
"
1.) Non-integer constants are ... constants that are not integer number.
Example: 'string1'
represents
a string constant
0x01
represents
a varbinary constant
{ts
'2015-02-26 06:00:00'}
represents a datetime constant
1.23
represents
a numeric constants
2) So single quotes are used to define a string constants / character string constants but SQL Server allows also to use single quotation marks use also as column identifier delimiter:
SELECT... expression AS'Column1'FROM...
In this context is clear that 'Column1'
is
a column identifier but when used in ORDER BY : ORDER
BY 'Column1'
it generates confusion because SQL Server doesn't knows if it represents a string literal (character string constant) or it represents a column identifier / column name."
Do I still need to change the existing code even though it's working fine in 2012? If yes, it is because of best practice reason or it will total get deprecated/not working in the future version?
Also, to resolve the issue I can use brackes?
ORDER BY [full name]?
Many thanks.