declare @a int,@b varchar(8000)
select @a=0,@b=''
select @a=@a+金额,@b=@b+备注
from 表
select 金额=@a,备注=@b

解决方案 »

  1.   

    --需要一个自定义函数处理create function f_getStr()
    returns varchar(1000)
    as
    begin
          declare @str varchar(1000)
          set @str=''
          select @str=@str+备注 from tt1
          return @str
    end
    --测试数据create table tt1(金额 int,备注 varchar(10))
    insert tt1 select 1000,'tt1'
    union all select 2000,'tt2'
    union all select 300,'tt3'--测试select sum(金额) as 金额,备注=dbo.f_getStr() from tt1/*
    --测试结果金额        备注
    3300        tt1tt2tt3*/--删除测试drop table tt1
      

  2.   

    select tt1+tt2+tt13 from  表
      

  3.   

    dim rs as new adodb.recordset
    sql="set nocount on;declare @a int,@b varchar(8000)" & vbcrlf & _
        "select @a=0,@b='' " & vbcrlf & _
        "select @a=@a+金额,@b=@b+备注 from 表 " & vbcrlf & _
        "select 金额=@a,备注=@b "rs.open sql,conn 'conn是你的数据库连接
    debug.print "金额:" & rs("金额") & "    备注:" & rs("备注")
    rs.close
      

  4.   

    你把函数写在SQL里,在VB中直接一个SQL语句就调用了,很方便的!
      

  5.   

    不好意思,这个SQL语句要在VB中调用,能否给出VB的写法。
      

  6.   

    因为后台数据库可能是SQL,也可能是ACCESS。