I have a column in my query for which I want to use its alias name.
Currently it is looking like this:
SELECT U.first_name + ' ' + U.last_name UserName,
But I want to use it as like below
SELECT U.first_name + ' ' + U.last_name as User Name,
I tried but I got error as:
Incorrect syntax near the keyword 'User'.
If the alias_name contains spaces, you must enclose the alias_name in quotes. It is acceptable to use spaces when you are aliasing a column name. However, it is not generally good practice to use spaces when you are aliasing a table name. The alias_name is only valid within the scope of the SQL statement.
Blanks spaces are restricted in the naming convention of the database object's name and column name of the table. If you want to include the blanks space in the object name or column name, the query and application code must be written differently. You must be careful and precise while writing dynamic SQL queries.
To create a table with a space in the table name in MySQL, you must use backticks otherwise you will get an error.
In many SQL relational database you will have to use the RPAD function to insert spaces into a character string. That also works in Vertica. However, for a more robust solution, Vertica provides the built-in function SPACE which returns the specified number of blank spaces.
Try This
SELECT U.first_name + ' ' + U.last_name as [User Name]
Double quotes for alias with a space.
SELECT U.first_name + ' ' + U.last_name AS "User Name"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With