31  
查询码:00001056
sql优化字符
作者: 刘波 于 2025年02月24日 发布在分类 / 小精灵pro 下,并于 2025年02月25日 编辑
优化字符



--查询名称有退格键
select * from t_bd_item_info  where charindex(char(8),item_name) > 0 
go


--查询名称有制表符tab 
select * from t_bd_item_info  where charindex(char(9),item_name) > 0 
go
--查询名称有换行  
select * from t_bd_item_info where charindex(char(10),item_name) > 0 
go
--查询名称有回车  
select * from t_bd_item_info where charindex(char(13),item_name) > 0 
go
--查询名称的空格(前空格、后空格、所有空格)
select * from t_bd_item_info where isnull(charindex(' ',item_name),0) > 0   
go
--查询名称的单引号 
select * from t_bd_item_info where charindex(char(39),item_name) > 0 
go
--查询名称的双单引号 
select * from t_bd_item_info where charindex(char(34),item_name) > 0 
go

 


--处理名称有退格键
update t_bd_item_info set item_name = replace(item_name,char(8),'') 
where charindex(char(9),item_name) > 0 
go


--处理名称有制表符tab 
update t_bd_item_info set item_name = replace(item_name,char(9),'') 
where charindex(char(9),item_name) > 0 
go
--处理名称有换行  
update t_bd_item_info set item_name = replace(item_name,char(10),'') 
where charindex(char(10),item_name) > 0 
go
--处理名称有回车  
update t_bd_item_info set item_name = replace(item_name,char(13),'') 
where charindex(char(13),item_name) > 0 
go
--处理名称的空格(前空格、后空格、所有空格)
update t_bd_item_info set item_name = replace(rtrim(ltrim(item_name)),' ','')  
where isnull(charindex(' ',item_name),0) > 0   
go
--处理名称的单引号 
update t_bd_item_info set item_name = replace(item_name,char(39),'') 
where charindex(char(39),item_name) > 0 
go
--处理名称的双单引号 
update t_bd_item_info set item_name = replace(item_name,char(34),'') 

where charindex(char(34),item_name) > 0 
go

---循环查询字符
WITH NumberCTE AS (
    SELECT 1 AS Number
    UNION ALL
    SELECT Number + 1 FROM NumberCTE WHERE Number < 100
)
SELECT CHAR(number) FROM NumberCTE;




 推荐知识

 历史版本

修改日期 修改人 备注
2025-02-25 16:39:04[当前版本] 刘波 格式调整
2025-02-24 10:15:33 刘波 格式调整
2025-02-24 10:15:24 刘波 创建版本

联拓知识分享平台 -V 4.7.0 -wcp