sql查询空格字段
‘壹’ sql 如何查询 空值的字段
sql查询空值的字段写法:SELECT A.字段 FROM student A WHERE A.字段 LIKE'% %' (student为表名)
查询类似空值的写法:
1、查询名称有退格键:select * from t_bd_item_info where charindex(char(8),item_name) > 0 go
2、查询名称有制表符tab:select * from t_bd_item_info where charindex(char(9),item_name) > 0 go
3、查询名称有换行:select * from t_bd_item_info where charindex(char(10),item_name) > 0 go
4、查询名称有回车:select * from t_bd_item_info where charindex(char(13),item_name) > 0 go
5、查询名称的空格(前空格、后空格、所有空格):select * from t_bd_item_info where isnull(charindex(' ',item_name),0) > 0go
6、查询名称的单引号:select * from t_bd_item_info where charindex(char(39),item_name) > 0 go
7、查询名称的双单引号:select * from t_bd_item_info where charindex(char(34),item_name) > 0 go
(1)sql查询空格字段扩展阅读
1、处理名称有退格键
update t_bd_item_info set item_name = replace(item_name,char(8),'')
where charindex(char(9),item_name) > 0 go
2、处理名称有制表符tab
update t_bd_item_info set item_name = replace(item_name,char(9),'')
where charindex(char(9),item_name) > 0 go
3、处理名称有换行
update t_bd_item_info set item_name = replace(item_name,char(10),'')
where charindex(char(10),item_name) > 0 go
4、处理名称有回车
update t_bd_item_info set item_name = replace(item_name,char(13),'')
where charindex(char(13),item_name) > 0 go
5、处理名称的空格(前空格、后空格、所有空格)
update t_bd_item_info set item_name = replace(rtrim(ltrim(item_name)),' ','')
where isnull(charindex(' ',item_name),0) > 0go
6、处理名称的单引号
update t_bd_item_info set item_name = replace(item_name,char(39),'')
where charindex(char(39),item_name) > 0 go
7、处理名称的双单引号
update t_bd_item_info set item_name = replace(item_name,char(34),'')
where charindex(char(34),item_name) > 0 go
‘贰’ sql 2008 怎么查询指定带空格的数据 比如:要查的值是 张 三 张三中间的空格要怎么表示
sql应该是 where xxx like '%aaa%' or xxx like '%bbb%' or...
C#怎么拼接自己照着拼就是
‘叁’ 怎么判断sql server中某字段含空格
使用CHARINDEX字符函数可以判断某个字符在字段中的位置:
SELECT
CASE CHARINDEX(' ',STCD)
WHEN 0 THEN 'NO FOUND'
ELSE 'EXISTS'
END
FROM
(
SELECT ' ' STCD
)A
参考:
CHARINDEX
返回字符串中指定表达式的起始位置。
语法
CHARINDEX ( expression1 , expression2 [ , start_location ] )
参数
expression1
一个表达式,其中包含要寻找的字符的次序。expression1 是一个短字符数据类型分类的表达式。
expression2
一个表达式,通常是一个用于搜索指定序列的列。expression2 属于字符串数据类型分类。
start_location
在 expression2 中搜索 expression1 时的起始字符位置。如果没有给定 start_location,而是一个负数或零,则将从 expression2 的起始位置开始搜索。
返回类型
int
注释
如果 expression1 或 expression2 之一属于 Unicode 数据类型(nvarchar 或 nchar)而另一个不属于,则将另一个转换为 Unicode 数据类型。
如果 expression1 或 expression2 之一为 NULL 值,则当数据库兼容级别为 70 或更大时,CHARINDEX 返回 NULL 值。当数据库兼容级别为 65 或更小时,CHARINDEX 仅在 expression1 和 expression2 都为 NULL 时返回 NULL 值。
如果在 expression2 内没有找到 expression1,则 CHARINDEX 返回 0。
示例
第一个代码示例返回序列"wonderful"在 titles 表的 notes 列中开始的位置。第二个示例使用可选的 start_location 参数从 notes 列的第五个字符开始寻找"wonderful"。第三个示例显示了当 expression2 内找不到 expression1 时的结果集。
USE pubs
GO
SELECT CHARINDEX('wonderful', notes)
FROM titles
WHERE title_id = 'TC3218'
GO
-- Use the optional start_location parameter to start searching
-- for wonderful starting with the fifth character in the notes
-- column.
USE pubs
GO
SELECT CHARINDEX('wonderful', notes, 5)
FROM titles
WHERE title_id = 'TC3218'
GO
下面是第一个查询和第二个查询的结果集:
-----------
46
(1 row(s) affected)
USE pubs
GO
SELECT CHARINDEX('wondrous', notes)
FROM titles
WHERE title_id='TC3218'
GO
下面是结果集。
-----------
0
(1 row(s) affected)
‘肆’ sql 怎么查找中间有空格记录啊
'%%';
‘伍’ SQL server如何查出数据中间有空格的数据
SQL查询某字段带空格的数据
select * from 表名 where 字段名 like '%_ _%'
‘陆’ sql查询字段里有空格
如果有空格可以用"[
nam
e]"(括号)标注即可;
sql:select
[file
name],
[file
name]
from
[table
name];
解释:括号通用于表面和字段,通过上面的语句就可以查询出“table
name”表中的“file
name”和“file
name”。
备注:尽量不要用空格,用“_”(下划线)
代替,更符合sql的命名规范。