select type,vendor,sum(pcs) from table where in_date >='2003/01/01' and in_date<='2003/03/03' group by type,vendor

解决方案 »

  1.   

    sorry,理解错了,应该是:
    select type,sum(pcs) from table where in_date >='2003/01/01' and in_date<='2003/03/03' and vendor='YY' group by type
      
      

  2.   

    select type,MAX(vendor),sum(pcs) from table where in_date >='2003/01/01' and in_date<='2003/03/03' group by type,vendor
      

  3.   

    楼主,最好的方法应该是:
    select type,sum(pcs) from table where in_date >=#2003/01/01# and in_date<=#2003/03/03# and vendor='YY' group by type
    如用"号会数据自动格式化为sring型来比较!
      

  4.   

    谢谢各位!
    另有一问题:存储过程如下
    CREATE PROCEDURE stock_01 
    @s_sdate as datetime,
    @s_edate as datetime,
    @s_vendor as varchar
    AS
    select type,vendor,sum(pcs) as pcs from table 
    where in_date >=@s_sdate and in_date<=@s_edate and in_ven=@s_vendor 
    group type,vendor
    GO
    在VB中调用时这样写为什么不行??
    dim Stadate,Enddate,Vendor as string
    gcnn.Execute ("insert into p_table exec stock_01  '" & Stadate & "','" & Enddate & "','" & Vendor & "'") '''调用存储过程
      

  5.   

    @s_sdate as datetime?
    dim Stadate,Enddate,Vendor as string
    类型不一致
     '" & Stadate & "'
     #" & Stadate & "#
      

  6.   

    transform sum(pcs)
    select type 
    from tab_name
    where in_date between date1 and date2
    group by type
    pivot vendor这个sql 生成如下表:
    type    yy   qq    ...
    ----------------------
    a1      2     4    ...
    b1      3     1    ...
    ...     ...   ...  ...希望对你有用.
      

  7.   

    jintianatxd(tian) ,你的这个对我很有用,能给我讲讲它的这个代码的原理吗?
      

  8.   

    你可以用ADO来执行存储过程:
      数据库是用的sql server 2000  
      Dim ldb As ADODB.Connection
      Dim lcmd As ADODB.Command
      '注意在vb中没有datetime数据类型,可用date类型代替
      Dim Stadate,Enddate as Date
      Dim Vendor As string
      
      Set ldb = New ADODB.Connection
      '主要是注意这个连接字符串,可以改变
      ldb.ConnectionString = "provider = sqloledb;" & _
                  "data source=flashstar;initial catalog= WTQU"
      ldb.Properties("User Id").Value = "sa"
      ldb.Properties("Password").Value = "sa"
      ldb.Open
      Set lcmd = New ADODB.Command
      Set lcmd.ActiveConnection = ldb
      lcmd.CommandText = "stock_01"  '存储过程名字
      lcmd.CommandType = adCmdStoredProc ‘命令类型
      lcmd.Parameters.Refresh
      '传递参数
      lcmd.Parameters("@s_sdate").Value = Stadate 
      lcmd.Parameters("@s_edate").Value = Enddate
      lcmd.Parameters("@s_vendor").Value = Vendor 
      lcmd.Execute