怎样取数字字符串开头的区间?

leitnt 2009-10-09 10:33:06
如果有这样一个表:

**** **** ccode
---- ---- ----------
…… …… 01*******
…… …… 01*******
…… …… 01*******
…… …… 02*******
…… …… 02*******
…… …… 03*******
…… …… 04*******
…… …… 05*******
…… …… 06*******
…… …… 06*******
…… …… 07*******
-------------------------
我想取02开头至06开头(共7条)的数据,应该怎么写?

我试过:
select * from table where ccode between '02*' and '06*'
好像不行
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixiaoshashou 2009-10-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bancxc 的回复:]
SQL codeselect*fromtablewheresubstring(ccode,1,2)between'02'and'06'
[/Quote]
还在继续学习中
rucypli 2009-10-09
  • 打赏
  • 举报
回复
where like '0[2-6]%'
bancxc 2009-10-09
  • 打赏
  • 举报
回复
select * from table where substring(ccode,1,2) between '02' and '06' 
lunzi028 2009-10-09
  • 打赏
  • 举报
回复

declare @table table (ccode varchar(50))

insert into @table
select '01*******' union all
select '01*******' union all
select '01*******' union all
select '02*******' union all
select '02*******' union all
select '03*******' union all
select '04*******' union all
select '05*******' union all
select '06*******' union all
select '06*******' union all
select '07*******'

select * from @table
where left(ccode,2)>='02' and left(ccode,2)<='06'
7761098 2009-10-09
  • 打赏
  • 举报
回复
select * from table where left(ltrim(ccode),2) between '02' and '06'

但是效率不高

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧