4

我在一家对冲基金工作,我们的数据库系统最近开始出现问题。我做了一些调查,实现了错误代码以及每个进程之间的消息框。我终于找到了问题所在:它似乎在 SQL 的存储过程中。

我们在 Windows XP SP3 上使用 VB 2005、Access for SQL 表视图和 Microsoft Server Management Studio Express。

其他所有过程都在工作。以下是它的工作原理:

我们填写了来自Bloomberg 的交易,该交易创建了一个.csv 文件。这个 .csv 文件被放入一个名为 BBGT_Transactions 的 SQL 表中。是直接复制。这个过程完美无缺。每次流程运行时(每 30 分钟),事务都在那里。接下来,相同的流程将事务处理在 BBGT_Transactions 中并将其复制到 Transactions。来自 VB 的调用如下所示:

 Public Sub CopyNewEMSTransactions()

        Log.Info("Copying new transactions from BBGTransactions to Transactions")
        DAL.sqlcmd("CopyNewEMSTransactions")

End Sub

CopyNewEMSTransactions 是一个存储过程,如下所示:

USE [IPAS]
GO
/****** Object:  StoredProcedure [dbo].[CopyNewEMSTransactions]    Script Date: 10/28/2013 13:34:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      Name
-- Create date: 
-- Description: 
-- =============================================
ALTER PROCEDURE [dbo].[CopyNewEMSTransactions] 
    -- Add the parameters for the stored procedure here
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here

--New Code: Accounts for option trades through bloomberg terminal
INSERT INTO Transactions (Account, TDate, [Time], SDate, Class,
                              [Type], Ticker, Quantity, Price, SEDOL,
                              CUSIP, Comments, OrderNumber, ISIN)
    SELECT TranAccount AS Account,
           (SELECT CAST(FLOOR(CAST(ExecDate AS float)) AS datetime)) AS TDate,
           ExecDate + ExecTime - '1899-12-30' AS [Time],
           ExecDate + 3 AS SDate, CASE EMS.Broker
                                    WHEN 'CIBC' THEN 'Equity'
                                    WHEN 'CIBO' THEN 'Option' END AS Class,
          CASE Side
            WHEN 'SS' THEN 'SHORT'
            WHEN 'B' THEN 'BUY'
            WHEN 'S' THEN 'SELL'
            WHEN 'BS' THEN 'BUY'
            ELSE 'UNKNOWN' 
          END AS Type, EMS.Ticker,
          CASE Side
            WHEN 'SS' THEN -1
            WHEN 'S' THEN -1
            WHEN 'B' THEN 1
            WHEN 'BS' THEN 1
          END * FillAmount AS Quantity, 
          AveragePrice AS Price,
          SEDOL, CUSIP,
          Comments = 'Bloomberg data',
          LatestRows.OrderNumber, ISIN
    FROM    
        (SELECT Ticker, OrderNumber, MAX(ExecSeqNumber) AS LastExecSeqNumber
        FROM BBGTransactions
        WHERE OrderNumber NOT IN (SELECT OrderNumber FROM Transactions 
                                  WHERE Comments = 'Bloomberg data')

        GROUP BY OrderNumber, Ticker) LatestRows
    LEFT JOIN
        --Changed from "SELECT * From BBGTransactions" to add the ' Equity'
        (SELECT BBG_ID, ExecDate, ExecTime, TranAccount, 
            CASE Broker
                WHEN 'CIBC' THEN Ticker
                WHEN 'CIBO' THEN Ticker + ' Equity' END AS Ticker,
        --With option trades, SEDOL is not used anywhere. It used to be used for the Reconciliation report
        --but that report has been changed to look at option ticker instead.
        CASE Broker
            WHEN 'CIBC' THEN SEDOL
            WHEN 'CIBO' THEN NULL END AS SEDOL, 
        CUSIP, OrderNumber, Side, FillAmount, AveragePrice, ExecLastFillPX, Broker, Currency, OrderType, 
        LimitPrice, DayFillAmount, DayAvgPrice, ISIN, Amount, ExecType, ExecSeqNumber, ExecPrevSeqNumber FROM BBGTransactions) EMS
    ON LatestRows.LastExecSeqNUmber = EMS.ExecSeqNumber
       AND LatestRows.OrderNumber = EMS.OrderNumber
    WHERE LatestRows.OrderNumber NOT IN (SELECT OrderNumber FROM Transactions 
                              WHERE Comments = 'Bloomberg data')

END

它不返回错误并显示“将 BBGT 复制到事务表”,然后显示“完成”但不复制!!它工作了 7 年,大约 3 周前停止工作。

要记住的事情:

  • 上个月我们的网络断断续续
  • 我怀疑 Windows 更新已经运行,并且在此之前大约 3 年以上没有更新 Windows。我上次检查时有 70 个更新,现在没有了。
  • 回到鬼魂是我最后的手段,因为这需要我做很多工作才能实现
  • 没有代码被改变过!
  • 我试过只运行存储过程,但它什么也不做,正如怀疑的那样。

编辑 有一个跟踪日志,只运行该过程。它没有返回错误吗?

SELECT SYSTEM_USER
go
SET ROWCOUNT 0 SET TEXTSIZE 2147483647 SET NOCOUNT OFF SET CONCAT_NULL_YIELDS_NULL ON SET ARITHABORT ON SET LOCK_TIMEOUT -1 SET QUERY_GOVERNOR_COST_LIMIT 0 SET DEADLOCK_PRIORITY NORMAL SET TRANSACTION ISOLATION LEVEL READ COMMITTED SET ANSI_NULLS ON SET ANSI_NULL_DFLT_ON ON SET ANSI_PADDING ON SET ANSI_WARNINGS ON SET CURSOR_CLOSE_ON_COMMIT OFF SET IMPLICIT_TRANSACTIONS OFF SET QUOTED_IDENTIFIER ON
go
select @@spid select SERVERPROPERTY('ProductLevel')
go
USE [IPAS]

go

DECLARE @return_value int

EXEC    @return_value = [dbo].[CopyNewEMSTransactions]

SELECT  'Return Value' = @return_value


go
exec sp_execute 18,5930,5924,5925,5926,5927,5928,5929,5923,5921,5922
go
exec sp_execute 16,59826,59827,59756,59757,59758,59716,59715,59700,59701,59702
go

另外,对应的excel表:

http://i.imgur.com/Ce76EHd.png

链接,以防很难看到:

http://i.stack.imgur.com/iJFRo.png


选择语句#1(似乎正在工作):

SELECT Ticker, OrderNumber, MAX(ExecSeqNumber) AS LastExecSeqNumber
FROM BBGTransactions
WHERE OrderNumber NOT IN (SELECT OrderNumber FROM Transactions
                          WHERE Comments = 'Bloomberg data')
GROUP BY OrderNumber, Ticker

返回: http://imgur.com/3A8E1JR

链接:http: //imgur.com/3A8E1JR

选择2:

代码:

SELECT BBG_ID, ExecDate, ExecTime, TranAccount,
    CASE Broker
        WHEN 'CIBC' THEN Ticker
        WHEN 'CIBO' THEN Ticker + ' Equity' END AS Ticker,
    --With option trades, SEDOL is not used anywhere. It used to be used for the Reconciliation report
    --but that report has been changed to look at option ticker instead.
    CASE Broker
        WHEN 'CIBC' THEN SEDOL
        WHEN 'CIBO' THEN NULL END AS SEDOL,
    CUSIP, OrderNumber, Side, FillAmount, AveragePrice, ExecLastFillPX, Broker, Currency, OrderType,
    LimitPrice, DayFillAmount, DayAvgPrice, ISIN, Amount, ExecType, ExecSeqNumber, ExecPrevSeqNumber 
    FROM BBGTransactions
    WHERE LatestRows.OrderNumber NOT IN (SELECT OrderNumber FROM Transactions
                                         WHERE Comments = 'Bloomberg data')

ERROR Server: Msg 4104, Level 16, State 1, Line 1 无法绑定多部分标识符“LatestRows.OrderNumber”。

4

3 回答 3

2

您为对冲基金工作,获得标准许可证并且不使用免费赠品。

看起来您发布的不是实际的存储过程,而是一个“清理过的”版本来展示它是如何工作的。这实际上是一种阻碍,而不是一种帮助。

在此删除时很难说,但我会说您遇到了数据问题(查询完全按照以往的方式运行,但您拥有的数据没有返回任何结果),或者您最终超出了构建的限制进入快递版。

忘记运行 SP,提取查询并直接运行它们,感受一下数据的实际样子。如果选择有效但插入无效,您可能已经超出了快速版本的限制。如果选择没有返回预期的行,那么您有数据问题。

于 2013-10-29T06:34:35.177 回答
1
-I have tried running ONLY the stored procedure and it does nothing.

你期望它返回什么?它是否显示任何受影响的行?

NO CODE WAS CHANGED EVER

你确定架构没有改变吗?您是否尝试运行查询并亲自查看它是否有效?(在没有来自 SP 的插入命令的情况下运行 select)

您确定您使用的是正确的数据库吗?这也可以改变..

你确定你的VB代码真的完成了吗?我会在 SP 执行后尝试打印日志,这里可能有我们看不到的异常。

于 2013-10-28T17:47:53.727 回答
0

计算机不做“随机”。发生了一些变化,导致了意想不到的结果。单步执行代码是确定的唯一方法..

于 2016-09-06T14:49:19.747 回答