读书人

这个条件如何写

发布时间: 2012-01-15 22:57:48 作者: rapoo

这个条件怎么写?
如果表a中的

字段p(字符型)

A-769954
1-978663
.....类似

的第一位是数字则选出来

select * from a where ?????????

如果直接用substring会类型错误哦。。。

[解决办法]
select * from tablename where left(p,1) in ( '0 ', '1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ')
[解决办法]
create table #temp
(aa varchar(50))

insert into #temp
select 'A-1234 '
union all
select 'B-1234 '
union all
select '2-1234 '
union all
select '3-1234 '

select * from #temp where left(aa,1) between '0 ' and '9 '

-----
aa

2-1234
3-1234

[解决办法]
where isnumeric(left(p,1))=1

读书人网 >SQL Server

热点推荐