stack stack - 3 months ago 10
SQL Question

Giving alias name with space in sql

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'.

Answer

Double quotes for alias with a space.

SELECT U.first_name + ' ' + U.last_name AS "User Name"