如何在SQL Server中处理列名称中的空格? [英] How do you deal with blank spaces in column names in SQL Server?

查看:644
本文介绍了如何在SQL Server中处理列名称中的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要使用下面的代码:

 选择响应状态代码 b $ b来自TC_Sessions(NOLOCK)
WHERE StartDate BETWEEN '05 -15-2012'AND '06 -01-2012'
AND supplyID = 3367

如何在SQL Server中执行此操作?



谢谢! (NOLOCK)选择[响应状态代码],[客户响应状态代码]
,然后选择[响应状态代码]
WHERE StartDate BETWEEN '05 -15-2012'AND '06 -01-2012'
AND supplyID = 3367

将名称括在方括号中。



但是,最好避免名称中出现空格。它只是为你在路上创造更多的工作...


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!

解决方案

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

这篇关于如何在SQL Server中处理列名称中的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆