拓狼 - 1/11/2010 3:34:00 AM
将电子指示牌的数字如下:

附件:
您所在的用户组无法下载或查看附件转成后的数字如下:

附件:
您所在的用户组无法下载或查看附件要求:
1、使用基于集合的方式进行处理
2、不能使用表变量、临时表、while循环、自定义函数
3、可以使用CTE
说明:
1、电子指示牌的每个数字由9个格组成,即3*3个格
2、电子指示牌里仅使用空格、下划线或者竖线
3、每个指示牌的数字都是9位数字
4、可能有些指示牌的某一位显示的数字不对,对这种数字,用x代替
使用下面附件中的代码生成测试数据:

附件:
您所在的用户组无法下载或查看附件
zsforever - 1/12/2010 12:34:00 AM
DECLARE @t TABLE (id int, ScanNumber NVARCHAR(116))
INSERT INTO @t
SELECT 1,--> 000 007 059
'_ _ _ _ _ _ _ _ _
| || || || || | || ||_ |_|
|_||_||_||_||_| ||_| _| _|
' UNION
SELECT 2, --> 490 067 715
' _ _ _ _ _ _ _
|_||_|| || ||_ | | ||_
| _||_||_||_| | | | _|
' UNION
SELECT 3, --> 680 068 279
'_ _ _ _ _ _ _ _ _
|_ |_|| || ||_ |_| _| ||_|
|_||_||_||_||_||_||_ | _|
'
UNION
SELECT 4, --> 490 867 716
' _ _ _ _ _ _ _
|_||_|| ||_||_ | | ||_
| _||_||_||_| | | ||_|
' UNION
SELECT 5, --> X80 867 716
' _ _ _ _ _ _ _
| ||_|| ||_||_ | | ||_
| _||_||_||_| | | ||_|
'
UNION SELECT 6, --> 012 345 678
'_ _ _ _ _ _ _
| | | _| _||_||_ |_ ||_|
|_| ||_ _| | _||_| ||_|
';
with cte_splitgroup as
(
select id,id_h=1,b.number,Char=substring(' '+a.ScanNumber,27*0+0+b.number*3+1,3)
from @t a inner join
master.dbo.spt_values b on b.type='P' and b.number<9
union all
select id,id_h=2,b.number,Char=substring(' '+a.ScanNumber,27*1+1+b.number*3+2,3)
from @t a inner join
master.dbo.spt_values b on b.type='P' and b.number<9
union all
select id,id_h=3,b.number,Char=substring(' '+a.ScanNumber,27*2+2+b.number*3+3,3)
from @t a inner join
master.dbo.spt_values b on b.type='P' and b.number<9
)
,
cte_number as
(select number=0,String='
_
| |
|_|' union all select 1,'
|
|' union all select 2,'
_
_|
|_ ' union all select 3,'
_
_|
_|' union all select 4,'
|_|
|' union all select 5,'
_
|_
_|' union all select 6,'
_
|_
|_|' union all select 7,'
_
|
|' union all select 8,'
_
|_|
|_|' union all select 9,'
_
|_|
_|')
,
cte_r as
(
select a.id,a.number,Value=isnull(rtrim(d.number),'X')
from cte_splitgroup a inner join
cte_splitgroup b on a.id=b.id and a.number=b.number and a.id_h=1 and b.id_h=2 inner join
cte_splitgroup c on a.id=c.id and c.id_h=3 and a.number=c.number left join
cte_number d on char(13)+a.Char+char(13)+b.Char+char(13)+c.Char=d.String
)
,
cte_r1 as
(
select id,number,Value=cast(Value as varchar(9))
from cte_r where number=0
union all
select b.id,b.number,Value=cast(a.Value+b.Value as varchar(9))
from cte_r1 a inner join
cte_r b on a.id=b.id and b.number=a.number+1
)
select id,Value from cte_r1
where number=8
order by id
zsforever - 1/12/2010 9:14:00 PM

附件:
您所在的用户组无法下载或查看附件好像直接回复不了,上传个sql脚本
zsforever - 1/12/2010 9:14:00 PM

附件:
您所在的用户组无法下载或查看附件好像直接回复不了,上传个sql脚本
tieqilin - 5/4/2010 2:52:00 AM
:default1: :default1: 看看