日期:2014-05-17  浏览次数:20841 次

求更新的SQL 语句
查找出“目标”这列,取出就是在com之前的那个点,到com之前之前的那个点之间
注意com.cn                  
 URL                          目标
http://news.17173.com/      17173
http://mail.airland.com/     airland
http://wenku.baidu.com/      baidu
http://www.surveyhead.com/  surveyhead
http://photo.weibo.com/      weibo
http://webmail.mail.163.com/ 163
http://photo.renren.com/     renren
https://my.alipay.com/       alipay
http://s96.917st.com/        917st
http://bbs.egou.com/         egou
http://9yinbbs.woniu.com/   woniu
http://mail.qq.com/     qq
http://quan.51fanli.com/    51fanli
http://quote.eastmoney.com/  easymoney

------解决方案--------------------
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (URL nvarchar(56),目标 nvarchar(20))
insert into [TB]
select 'http://news.17173.com/','17173' union all
select 'http://mail.airland.com/','airland' union all
select 'http://wenku.baidu.com/','baidu' union all
select 'http://www.surveyhead.com/','surveyhead' union all
select 'http://photo.weibo.com/','weibo' union all
select 'http://webmail.mail.163.com/','163' union all
select 'http://photo.renren.com/','renren' union all
select 'https://my.alipay.com/','alipay' union all
select 'http://s96.917st.com/','917st' union all
select 'http://bbs.egou.com/','egou' union all
select 'http://9yinbbs.woniu.com/','woniu' union all
select 'http://mail.qq.com/','qq' union all
select 'http://quan.51fanli.com/','51fanli' union all
select 'http://quote.eastmoney.com/','easymoney'

select * from [TB]


SELECT url,REVERSE(SUBSTRING(REVERSE(REPLACE(url,'.com/','')),0,PATINDEX('%.%',REVERSE(REPLACE(url,'.com/','')))))
FROM TB

/*
url (无列名)
http://news.17173.com/ 17173
http://mail.airland.com/ airland
http://wenku.baidu.com/ baidu
http://www.surveyhead.com/ surveyhead
http://photo.weibo.com/ weibo
http://webmail.mail.163.com/ 163
http://photo.renren.com/ renren
https://my.alipay.com/ alipay
http://s96.917st.com/ 917st
http://bbs.egou.com/ egou
http://9yinbbs.woniu.com/ woniu
http://mail.qq.com/ qq
http://quan.51fanli.com/ 51fanli
http://quote.eastmoney.com/ eastmoney*/

------解决方案--------------------
借用l楼的表。

select url,目标=parsename(url,2) from tb