ADO 2.5调用SQL Server存储过程从标量函数返回空白数据

时间:2012-05-17 19:12:40

标签: sql-server vb6 ado

我有一个用VB6编写的遗留应用程序,使用ADO 2.5与SQL Server 2008数据库通信。其中包含一个从存储过程中获取数据的报告。存储过程调用UDF,该UDF将varchar结果作为结果集的一列返回。从SQL Server Management Studio调用它时,它会正确填充该列,但是当从VB6应用程序中调用它时,它会返回一个空值。是否存在可能导致此问题的兼容性问题?

这是UDF:

ALTER FUNCTION dbo.TransferNoteAgreementSummary(@ClientID int, @Year int) 
RETURNS varchar(3000) AS
BEGIN
    DECLARE @ret varchar(3000)
    SET @ret=''

    SELECT @ret = @ret +  
        + CONVERT(varchar, F.NumBins) + ' of ' + B.[Name]+', '+CONVERT(varchar, F.DaysPerWeek)+' lifts, ' + CF.Frequency 
        + ' from ' + CONVERT(varchar, F.StartDate,106)+' to '+CONVERT(varchar, F.EndDate, 106) + dbo.CrLf()
    FROM Accounts A
        JOIN AccountFragments F ON A.AccountID=F.AccountID
        JOIN BinTypes B ON A.BinTypeID=B.BinTypeID
        JOIN ContractFrequencies CF ON F.FrequencyID=CF.FrequencyID
    WHERE A.ClientID=@ClientID AND A.ContractYear=@Year
    ORDER BY B.[Name], A.AccountID, F.StartDate

    RETURN @ret
END

以下是存储过程的相关部分:

ALTER PROC [dbo].[sp_PrintRoundsReport]
AS

          DECLARE @Year int
    DECLARE @Results TABLE([Route] VARCHAR(100), Town VARCHAR(200), ClientID INT, Customer VARCHAR(400), [Address] VARCHAR(MAX),
                                                    [Item Code] VARCHAR(50), Bins INT, [Type] VARCHAR(40), Volume INT, BinDesc VARCHAR(3000), 
                                                    CollectDay VARCHAR(20), DayOrder int)

[ irrelevant lines removed ]                                                    

    SELECT [Route], Town, Customer, [Address], [Item Code], Bins, [Type], Volume, 
        dbo.TransferNoteAgreementSummary(ClientID, @Year) AS BinDesc, CollectDay
    FROM @Results
    ORDER BY DayOrder, [Route], Town, [Address], Volume

最后,这里是被调用的代码:

  Set cmd = New ADODB.Command
  Set cmd.ActiveConnection = GetConnectionString() 

  cmd.CommandType = adCmdStoredProc
  cmd.CommandText = "sp_PrintRoundsReport"

  Dim rs As New Recordset

  Call rs.Open(cmd)

问题似乎与功能有关。如果我将其更改为返回一个常量字符串,那么该值将正确传递

这会给任何人敲响声吗?

1 个答案:

答案 0 :(得分:0)

你不是不知道的吗?

cmd.Parameters.Add("@RETURN_VALUE")