ID    bigID(大类)  smallID(小类)
1066    4             14
1067    4             14
1069    7             16
1070    7             16
1071    7             16
1072    7             17
表tabel2
id        EID(表tabel1中ID)                    EValue(分数)
1    1069,1070,1071,1072,1066,1067,         10,10,10,10,10,10,
2    1069,1070,1071,                        10,10,10,
3    1066,1067,1068,                        10,6,6, 
现在我想统分别计出来小类的分数和大类分数?   怎么做?谢谢了

解决方案 »

  1.   

     表tabel1 
    ID/ bigID(大类)/ smallID(小类)
    1066 /4 /14
    1067 /4/ 14
    1069 /7 /16
    1070 /7 /16
    1071 /7 /16
    1072 /7 /17
    表tabel2
    id /EID(表tabel1中ID) /EValue(分数)
    1 /1069,1070,1071,1072,1066,1067,/ 10,10,10,10,10,10,
    2 /1069,1070,1071,/ 10,10,10,
    3 /1066,1067,1068,/ 10,6,6, 
    上述参考数据系统排版有问题  所以用"/"分开 分别统计出来小类的分数和大类分数?怎么实现  谢谢了
      

  2.   

    给你贴2个function把
    create function [dbo].[Get_StrArrayLength]
    (
      @str varchar(1024),  
      @split varchar(10)  
    )
    returns int
    as
    begin
      declare @location int
      declare @start int
      declare @length int   set @str=ltrim(rtrim(@str))
      set @location=charindex(@split,@str)
      set @length=1
      while @location<>0
      begin
    set @start=@location+1
    set @location=charindex(@split,@str,@start)
    set @length=@length+1
      end
      return @length
    end
    ---用来获取字符串按照分隔符拆分后总共有几个数据,类似于取数组中的长度
    create function [dbo].[Get_StrArrayStrOfIndex]
    (
      @str varchar(1024),  
      @split varchar(10),  
      @index int 
    )
    returns varchar(1024)
    as
    begin
      declare @location int
      declare @start int
      declare @next int
      declare @seed int   set @str=ltrim(rtrim(@str))
      set @start=1
      set @next=1
      set @seed=len(@split)
      
      set @location=charindex(@split,@str)
      while @location<>0 and @index>@next
      begin
    set @start=@location+@seed
    set @location=charindex(@split,@str,@start)
    set @next=@next+1
      end
      if @location =0 select @location =len(@str)+1
    return substring(@str,@start,@location-@start)
    end
    -----用来获取按照分隔符取出字符串中第几个数据,类似与取出数组中在第几个位置的数据
      

  3.   

    @StrLength = dbo.Get_StrArrayLength(@Str,',')
    while(@StrLength is not null  and @StrLength>0)
    begin
    select @StrChild = dbo.Get_StrArrayStrOfIndex(@Str,',',@StrLength)

    --分数统计操作

    set @StrLength = @StrLength - 1
    end
      

  4.   

    ---分数统计操作部分
     在while操作的时候你可以拆分出1069  1070 这样的单个数据
        然后根据表一中大类和小类分数相加。