Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you deal with blank spaces in column names in SQL Server?

Tags:

Suppose I want to use code like this:

select 'Response Status Code', 'Client Response Status Code'  from TC_Sessions (NOLOCK) WHERE StartDate BETWEEN '05-15-2012' AND '06-01-2012' AND SupplyID = 3367 

How do you do this in SQL Server?

thank you!

like image 965
Caffeinated Avatar asked Jun 06 '12 19:06

Caffeinated


People also ask

How do you handle column names with spaces in SQL?

To select a column name with spaces, use the back tick symbol with column name. The symbol is ( ` `). Back tick is displayed in the keyboard below the tilde operator ( ~).

How do I remove blank spaces in SQL column?

SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string. Note: Also look at the LTRIM() and RTRIM() functions.

Can SQL Server column names have spaces?

Column names can contain any valid characters (for example, spaces).

How does SQL handle spacing in names?

DML SQL query with space in a column name When we run INSERT, UPDATE, and DELETE statements, we must use a square bracket or double quotes to handle the column name with space.


1 Answers

select [Response Status Code], [Client Response Status Code] from TC_Sessions (NOLOCK)  WHERE StartDate BETWEEN '05-15-2012' AND '06-01-2012'  AND SupplyID = 3367  

Wrap the names in square brackets.

It is , however, best to avoid spaces in names if possible. It just creates more work for you down the road...

like image 120
Jimbo Avatar answered Oct 20 '22 22:10

Jimbo