2

我有一个用 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)

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

这会为任何人敲响警钟吗?

4

1 回答 1

0

你不是失踪了吗?

cmd.Parameters.Add("@RETURN_VALUE")
于 2012-07-26T11:22:16.940 回答