如果數據是這樣的規律,可以偷下懶。
Create Table TEST
(序号 Int,
网站 Varchar(1000))
Insert TEST Select 1, 'chinaz chinaz chinaz chinaz chinaz'
Union All Select 2, 'sohu sohu sohu sohu sohu'
Union All Select 3, 'sina sina sina sina sina'
Union All Select 4, 'tom tom tom tom tom'
Union All Select 5, '163 163 163 163 163'
GO
Select
序号,
Left(网站,CharIndex(' ',网站)-1) As 网站
From TEST
GO
Drop Table TEST
GO
--Result
/*
序号 网站
1 chinaz
2 sohu
3 sina
4 tom
5 163
*/
Create Table TEST
(序号 Int,
网站 Varchar(1000))
Insert TEST Select 1, 'chinaz chinaz chinaz chinaz chinaz'
Union All Select 2, 'sohu sohu sohu sohu sohu'
Union All Select 3, 'sina sina sina sina sina'
Union All Select 4, 'tom tom tom tom tom'
Union All Select 5, '163 163 163 163 163'
GO
Select
序号,
Left(网站,CharIndex(' ',网站)-1) As 网站
From TEST
GO
Drop Table TEST
GO
--Result
/*
序号 网站
1 chinaz
2 sohu
3 sina
4 tom
5 163
*/
update 表名 set 网站=left(网站,charindex(' ',网站))
(序号 Int,
网站 Varchar(1000))
Insert TEST Select 1, 'chinaz chinaz chinaz chinaz chinaz'
Union All Select 2, 'sohu sohu sohu sohu sohu'
Union All Select 3, 'sina sina sina sina sina'
Union All Select 4, 'tom tom tom tom tom'
Union All Select 5, '163 163 163 163 163'
GO
Update TEST Set 网站=Left(网站,CharIndex(' ',网站)-1)Select * From TEST
GO
Drop Table TEST
GO
--Result
/*
序号 网站
1 chinaz
2 sohu
3 sina
4 tom
5 163
*/