我数据库有一个表 A(id name count)比如有3条记录 
                   (1   ati    50)
                   (2   msi    80)
                   (3   accer  90)
我现在要在一个页面输入  ati 30  accer 100
                        就要显示 ati  20  accer -10 怎么写呢

解决方案 »

  1.   

    SQL很好写,一个简单查询就行了,但是处理过程需要程序来判断,我想你还是去开发语言去找相应版问问看吧
      

  2.   

    create table A(id int,name varchar(10),[count] int)
    insert into A select 1,rtrim('ati  '),50
    insert into A select 2,rtrim('msi  '),80
    insert into A select 3,rtrim('accer'),90
    go--约定,name与[count]之间间隔1个空格' ',记录与记录之间间隔两个空格'  '
    create function f_str(@str varchar(8000))
    returns varchar(8000)
    as
    begin
        declare @t table(name varchar(10),[count] int)
        declare @chr varchar(60)
        set @str=@str+'  '
        
        while charindex('  ',@str)>0
        begin
            set @chr=left(@str,charindex('  ',@str)-1)
            set @str=stuff(@str,1,charindex('  ',@str)+1,'')
            
            insert into @t select left(@chr,charindex(' ',@chr)),stuff(@chr,1,charindex(' ',@chr),'')
        end
        
        set @str=''
        
        select 
            @str=@str+'  '+name+' '+rtrim([count]) 
        from 
            (select A.name,a.[count]-b.[count] as [count] from A,@t b where A.name=b.name) t
        
        set @str=stuff(@str,1,2,'')
        return @str
    end
    goselect dbo.f_str('ati 30  accer 100')
    godrop function f_str
    drop table A
    go