C# 开始因此,例如2中有一个“Y”,所以我们需要2000到2999之间的数字。您有没有可能更详细地介绍一下?我得到了第一个部分,但从“那么你需要一个源代码-脚本源代码或狡猾的OLEDB源代码”部分开始就有点迷失了! Range Location

C# 开始因此,例如2中有一个“Y”,所以我们需要2000到2999之间的数字。您有没有可能更详细地介绍一下?我得到了第一个部分,但从“那么你需要一个源代码-脚本源代码或狡猾的OLEDB源代码”部分开始就有点迷失了! Range Location ,c#,sql,sql-server,sql-server-2008,ssis,C#,Sql,Sql Server,Sql Server 2008,Ssis,开始因此,例如2中有一个“Y”,所以我们需要2000到2999之间的数字。您有没有可能更详细地介绍一下?我得到了第一个部分,但从“那么你需要一个源代码-脚本源代码或狡猾的OLEDB源代码”部分开始就有点迷失了! Range Location 0 1 2 3 4 5 6 7 8 9 01132 21 Leeds Y Y Y Y Y Y crea


开始因此,例如2中有一个“Y”,所以我们需要2000到2999之间的数字。您有没有可能更详细地介绍一下?我得到了第一个部分,但从“那么你需要一个源代码-脚本源代码或狡猾的OLEDB源代码”部分开始就有点迷失了!
Range       Location    0   1   2   3   4   5   6   7   8   9                   
01132 21    Leeds       Y       Y   Y       Y   Y       Y
create table #excel (
    range       nvarchar(7),
    location    nvarchar(20),
    col_0       nvarchar(1),
    col_1       nvarchar(1),
    col_2       nvarchar(1),
    col_3       nvarchar(1),
    col_4       nvarchar(1),
    col_5       nvarchar(1),
    col_6       nvarchar(1),
    col_7       nvarchar(1),
    col_8       nvarchar(1),
    col_9       nvarchar(1)
)

/*Use SSIS to load your Excel sheet in, instead of this insert*/
insert into #excel
values ('0113221', 'Leeds', 'Y', NULL, 'Y', 'Y', NULL, 'Y', 'Y', NULL, 'Y', NULL)


;with numbers as
(
    select 0 x
    union all
    select x + 1
    from numbers
    where x < 99
)
select e.location, e.range + '0' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_0 = 'Y'
union all
select e.location, e.range + '1' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_1 = 'Y'
union all
select e.location, e.range + '2' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_2 = 'Y'
union all
select e.location, e.range + '3' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_3 = 'Y'
union all
select e.location, e.range + '4' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_4 = 'Y'
union all
select e.location, e.range + '5' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_5 = 'Y'
union all
select e.location, e.range + '6' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_6 = 'Y'
union all
select e.location, e.range + '7' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_7 = 'Y'
union all
select e.location, e.range + '8' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_8 = 'Y'
union all
select e.location, e.range + '9' + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.col_9 = 'Y'
create table #excel (
    range       nvarchar(7),
    location    nvarchar(20),
    number      nvarchar(1),
    yes_no      nvarchar(1)
)

insert into #excel
values ('0113221', 'Leeds', '0', 'Y'),
    ('0113221', 'Leeds', '1', NULL),
    ('0113221', 'Leeds', '2', 'Y'),
    ('0113221', 'Leeds', '3', 'Y'),
    ('0113221', 'Leeds', '4', NULL),
    ('0113221', 'Leeds', '5', 'Y'),
    ('0113221', 'Leeds', '6', 'Y'),
    ('0113221', 'Leeds', '7', NULL),
    ('0113221', 'Leeds', '8', 'Y'),
    ('0113221', 'Leeds', '9', NULL)


;with numbers as
(
    select 0 x
    union all
    select x + 1
    from numbers
    where x < 99
)
select e.location, e.range + e.number + RIGHT('00' + CAST(n.x as nvarchar), 3)
from #excel e cross join
    numbers n
where e.yes_no = 'Y'