我在一家对冲基金工作,我们的数据库系统最近开始出现问题。我做了一些调查,实现了错误代码以及每个进程之间的消息框。我终于找到了问题所在:它似乎在 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.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
选择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”。