我有一字符串,该字符串的组成是这样的:年份+类别+号码。年份这一部分有可能是两位(如09),也有可能是4位(2009)。
举两个年份位数不同的字符串:(1)200913313001011(年份为4位,第5位表示类别)(2)0923313001012(年份为2位,第3位表示类别)。
求一个根据该字符串获取获取其类别的函数,请指教!
举两个年份位数不同的字符串:(1)200913313001011(年份为4位,第5位表示类别)(2)0923313001012(年份为2位,第3位表示类别)。
求一个根据该字符串获取获取其类别的函数,请指教!
解决方案 »
- 请教一sql查询,有多个表.
- 真怪了,新建一个数据库,竟然没有系统存贮过程,记得新建后,就该有很多系统自带的存贮过程的,为何?
- 有什么办法可以检查是不是索引有没问题
- 如何在drop table 后跟变量
- 安装AdventureWorks2008R2_SR1 出现"Full text search not running"
- 分享:数据表破坏后,修复表的方法!
- 一个匹配的问题?(解决马上给分!)
- 急急急??????????
- 请问sqlserver2000能装在windows2003webserver版上么,我怎么总是装不上??
- SQL Server2008默认日期格式设置
- 多表统计的问题
- 连本地数据库连不上。
create table #AA
(
sss varchar(30)
)
insert into #AA
select '200913313001011' union all
select '0923313001012'select (case when substring(sss,1,1)='2' then substring(sss,5,4) else substring(sss,3,4) end) as leixing from #AA
-------------------------
leixing
1331
2331
create table #AA
(
sss varchar(30)
)
insert into #AA
select '200913313001011' union all
select '0923313001012'select (case when substring(sss,1,1)='2' then substring(sss,5,1) else substring(sss,3,1) end) as leixing from #AA
leixing
-------
1
2(2 行受影响)
insert into tb values('200913313001011')
insert into tb values('0923313001012')
goselect left(col , len(col) - 11) 年,
left(right(col,11),1) 类别
from tbdrop table tb/*
年 类别
--------------- ----
2009 1
09 2(所影响的行数为 2 行)
*/
你给的数据里
年份+类别+号码
号码的长度是 10select right(left(fieldvalue,len(fieldvalue)-10),1) as '类别' from tb
insert @t select '200913313001011'
union all select '0923313001012'select col,(case when len(col)=15 then substring(col,5,1) else substring(col,3,1) end) type from @tcol type
-------------------- ----
200913313001011 1
0923313001012 2(2 行受影响)
set @s='200913313001011'
--set @s='0923313001012'
select substring(reverse(@s),11,1)
/*
1
*/
go
create table [tb]([编号] varchar(14))
insert [tb]
select '86300493' union all
select '92207560' union all
select '91226410' union all
select '00217636.X' union all
select '99336935.9' union all
select '00305178.1' union all
select '01328822.9' union all
select '200330101225.9' union all
select '03224068.6'--非严格方法:
select [编号],[对应年份]=left([完整编号],4),[对应类型]=substring([完整编号],5,1)
from
(
select [编号],[完整编号]=case when left([编号],2) in ('19','20') then [编号]
when left([编号],1)='0' then '20'+[编号]
else '19'+[编号]
end
from tb
) t
/*
编号 对应年份 对应类型
-------------- -------- ----
86300493 1986 3
92207560 1992 2
91226410 1991 2
00217636.X 2000 2
99336935.9 1999 3
00305178.1 2000 3
01328822.9 2001 3
200330101225.9 2003 3
03224068.6 2003 2(9 行受影响)*/