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!
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 ( ~).
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.
Column names can contain any valid characters (for example, spaces).
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.
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...
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