There are some aliases that aren't allowed for use in SQL, for example:
1. SQL Reserved words or key words
2. Function names
3. Aliases that start with a numeric digit
4. Aliases that have spaces.
To use aliases that match the above criteria, the user would need to escape them using double quotes.
SELECT CASE.CASE_ID FROM Administrator.SUPPORT_INCIDENTS CASE
The example above will generate a SQL syntax error. This is because CASE is a function name. It is a reserved word and it cannot be used as an alias. To make the above SQL statement work, the CASE word would need to be enclosed in double quotes like the example below.
SELECT "CASE".CASE_ID FROM Administrator.SUPPORT_INCIDENTS "CASE"
Do note that the double quotes would not be treated as a literal. The sample SQL statement below uses a numeric digit at the start of the column alias.
SELECT CASE_ID "10Case" FROM Administrator.SUPPORT_INCIDENTS;
And here is the result:
Without the double quotes, the query will throw a syntax error.
For aliases that have spaces, the user must enclose them with square brackets like the example below.
SELECT CASE_ID [Case Number] FROM Administrator.SUPPORT_INCIDENTS;
No comments:
Post a Comment