表Aug如下:  
DATE            SYMBOL  
2006-8-8            A  
2006-8-8            AA  
2006-8-8            AAP  
2006-8-8            ABC  
2006-8-8            ABI  
2006-8-8            ABK  
2006-8-8            ABMD  
2006-8-8            ABT  
......  
2006-8-9            A  
2006-8-9            AA  
2006-8-9            AAP  
2006-8-9            ABC  
2006-8-9            ABI  
2006-8-9            ABK  
2006-8-9            ABMD  
2006-8-9            ABT  
......

解决方案 »

  1.   

    create table Aug([DATE] smalldatetime,SYMBOL varchar(10))
    insert Aug select '2006-8-8',            'A'  
    union all select '2006-8-8',            'AA'  
    union all select '2006-8-8',            'AAP' 
    union all select '2006-8-8',            'ABC'  
    union all select '2006-8-8',            'ABI'  
    union all select '2006-8-8',            'ABK'  
    union all select '2006-8-8',            'ABMD'  
    union all select '2006-8-8',            'ABT'  union all select '2006-8-9',            'A'  
    union all select '2006-8-9',            'AA'  
    union all select '2006-8-9',            'AAP'  
    union all select '2006-8-9',            'ABC'  
    union all select '2006-8-9',            'ABI'  
    union all select '2006-8-9',            'ABK'  
    union all select '2006-8-9',            'ABMD'  
    union all select '2006-8-9',            'ABT'  declare @str varchar(10),@count1 int,@count2 int
    select @str='A',@count1=0,@count2=0
    select @count1=@count1+len(rtrim(ltrim(SYMBOL))) from Aug
    select @count2=@count2+len(replace(rtrim(ltrim(SYMBOL)),@str,'')) from Aug
    select @count1-@count2 as [@str字符串的数量]
    /*
    @str字符串的数量  
    ----------- 
    20*/
    drop table Aug