declare @i int //声明变量

set @i=1
while @i<=154  //需要处理的数据总数(行为单位)
begin
update [weilaixueyuan_db].[dbo].[Jft_xiaofangZH_Classify] set Content=(
select 
SUBSTRING ((select name from [weilaixueyuan_db].[dbo].[Jft_xiaofangZH_Classify] where Id=@i), 0 , 
(select CHARINDEX(' ',
(select name from [weilaixueyuan_db].[dbo].[Jft_xiaofangZH_Classify] where Id=@i),
0))) ) where Id=@i ;
set @i=@i+1
end



//上面是普通的sql更新语句,其中有两个字符串处理方法:
SUBSTRING ( character_expression , start , length )  
  1. 函数说明:SUBSTRING ( '源字符串' , '截取起始位置(含该位置上的字符)' , '截取长度' )  
  2. 返回字符、binary、text 或 image 表达式的一部分  
  3. select SUBSTRING('SQL_Server_2008',5 ,6);  
  4. 返回结果:Server
//PS 索引从1开始
2.CHARINDEX('需要匹配的字符串','源字符串','匹配位置')
select CHARINDEX('d','abcdefg',0)--4

  

相关文章:

  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案