技术开发 频道

关于报表显示的问题

    【IT168 MSSQL文档】有一报表
    a b c
    1 001 00
    1 002 00
    2 000 11
    2 001 22
    2 001 00
    要显示如下:
    a b c
    1 001 00
    002 00
    2 000 11
    001 22
    001 00
    
    ________________________________________
    作者:magicangel    时间:04-11-29 18:22
    --建表
    select '1' as a,'001' as b,'00' as c
    into #magic
    union all
    select '1','002','00'
    union all
    select '2','000','11'
    union all
    select '2','001','22'
    union all
    select '2','001','00'
   
    --加工格式
    select (case when tmp3.no=1 then tmp3.a else ' ' end) a,b,c from
    (select top 100000000 a,(select count(1) from #magic tmp1 where tmp1.a=tmp2.a and tmp1.b<=tmp2.b) as no,b,c
    from #magic tmp2 order by a,b,c) tmp3
   
    --如果a是数值型,那么加工查询里的else后跟null
   ________________________________________

    作者:luckw_001    时间:04-11-30 11:04
    quote:
    ________________________________________
    最初由 magicangel 发布
    --建表
    select '1' as a,'001' as b,'00' as c
    into #magic
    union all
    select '1','002','00'
    union all
    select '2','000','11'
    union all
    select '2','001','22'
    union all
    select '2','001','00'
   
    --加工格式
    select (case when tmp3.no=1 then tmp3.a else ' ' end) a,b,c from
    (select top 100000000 a,(select count(1) from #magic tmp1 where tmp1.a=tmp2.a and tmp1.b<=tmp2.b) as no,b,c
    from #magic tmp2 order by a,b,c) tmp3
   
    --如果a是数值型,那么加工查询里的else后跟null
    ________________________________________
   
    可是再加一个
    select '1','001','01'时
    却是:
    001 00
    001 01
    002 00
    2 000 11
    001 00
    001 22
    002 00
    以上结果. 
    ________________________________________
    作者:magicangel    时间:04-11-30 20:31
    quote:
    ________________________________________
    最初由 luckw_001 发布
   
    可是再加一个
    select '1','001','01'时
    却是:
    001 00
    001 01
    002 00
    2 000 11
    001 00
    001 22
    002 00
    以上结果. 
    ________________________________________
    
    
   考虑不周,改为如下:
   
    --建表
    select '1' as a,'001' as b,'00' as c
    into #tmp
    union all
    select '1','002','00'
    union all
    select '2','000','11'
    union all
    select '2','001','22'
    union all
    select '2','001','00'
    union all
    select '1','001','00'
    union all
    select '1','002','00'
   
    --人为加序列,序列用来辅助
    select identity(int) id,* into #magic from #tmp
   
    --加工格式
    select (case when tmp3.no=0 then tmp3.a else ' ' end) a,b,c from
    (select top 100000000 a,(select count(1) from #magic tmp1 where tmp1.a=tmp2.a and (tmp1.b+tmp1.id)<(tmp2.b+tmp2.id)) as no,b,c
    from #magic tmp2 order by a,b,c) tmp3
    ________________________________________
    作者:magicangel    时间:04-11-30 20:35
    如果执行
    select identity(int) id,* into #magic from #tmp
    这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开,请先执行:
    exec sp_dboption 你的DB名字,'select into/bulkcopy',true
    

    ________________________________________
    作者:luckw_001    时间:04-12-01 15:44
    quote:
    ________________________________________
    最初由 magicangel 发布
    如果执行
    select identity(int) id,* into #magic from #tmp
    这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开,请先执行:
    exec sp_dboption 你的DB名字,'select into/bulkcopy',true
    
 
    ________________________________________
    

    在:tmp1.b+tmp1.id<tmp2.b+tmp2._id中
    如果b是数字型字符是可以通过的
    但如果是字符型字符就通不过了.
    例:
    再加:2,0a1,00
    就会报错.
    以上错误能不能再改一下.谢谢!!!
    再:
    把tmp1.b+tmp1.id<tmp2.b+tmp2.id改
    为tmp1.a+tmp1.id<tmp2.a+tmp2.id
    a为数字型字符同样通过.
    ________________________________________
    作者:magicangel    时间:04-12-01 19:23
    select '1' as a,'001' as b,'00' as c
    into #tmp
    union all
    select '1','002','00'
    union all
    select '2','000','11'
    union all
    select '2','001','22'
    union all
    select '2','001','00'
    union all
    select '1','001','00'
    union all
    select '1','002','00'
    union all select '2','0a1','00'
   
    --人为加序列,序列用来辅助
    select identity(int) id,* into #magic from #tmp
   
    --加工格式
    select (case when tmp3.no=0 then tmp3.a else ' ' end) a,b,c from
    (select top 100000000 a,(select count(1) from #magic tmp1 where tmp1.a=tmp2.a and (cast(tmp1.b as varchar(100))+cast(tmp1.id as varchar(100)))<(cast(tmp2.b as varchar(100))+cast(tmp2.id as varchar(100)))) as no,b,c
    from #magic tmp2 order by a,b,c) tmp3
    ________________________________________
    作者:magicangel    时间:04-12-01 19:25
    用cast函数将字段都转换成字符型比较就可以了。
   
0
相关文章