select cast(content as int) as content from tb where len(content) > 5
从 content中取出有5-10位的数字的记录,比如qq号码
SELECT PATINDEX('%123%',content) FROM table模式:123 位置:PATINDEX返回值另:你的描述不是很清楚
select Col, patindex('%' + replicate('[0-9]', 10) + '%', Col) as [Index] from (select 'adsa1234567890asdfafds1234567890ads' as Col union select 'adsfasd' union select '1234567890') a where patindex('%' + replicate('[0-9]', 10) + '%', Col) > 0 /* Col Index ----------------------------------- ----------- 1234567890 1 adsa1234567890asdfafds1234567890ads 5*/
select cast(substring(content,5,6) as int) as xx from tablename
create table tb(content varchar(8000)) insert into tb select '31234567890' insert into tb select '0123456789' insert into tb select '012345678935343534' insert into tb select 'df2345678935sdfsad'select cast(substring(content,5,6) as int) as xx from tbdrop table tb 这个可以大于10位以上的啊
FROM table模式:123
位置:PATINDEX返回值另:你的描述不是很清楚
from (select 'adsa1234567890asdfafds1234567890ads' as Col
union select 'adsfasd'
union select '1234567890') a
where patindex('%' + replicate('[0-9]', 10) + '%', Col) > 0
/*
Col Index
----------------------------------- -----------
1234567890 1
adsa1234567890asdfafds1234567890ads 5*/
from tablename
insert into tb select '31234567890'
insert into tb select '0123456789'
insert into tb select '012345678935343534'
insert into tb select 'df2345678935sdfsad'select cast(substring(content,5,6) as int) as xx
from tbdrop table tb
这个可以大于10位以上的啊