我有两个 Microsoft Access 数据库表。它们被命名为Historical_Stock_Prices
和Balance_Sheets
。我需要组合这些表中的每一个表中的数据来创建一个名为Daily
. 我需要取字段Ticker
,[Date]
和[Close]
from Historical_Stock_Prices
,我需要取字段Common_Stocks
from Balance_Sheets
。
我不会从Historical_Stock_Prices
and中取出每一行Balance_Sheets
。我只会采用在DateTimePicker
命名中选择的日期上或之前的行dtpDateSelection
。
现在我遇到的主要问题是Historical_Stock_Prices
每天都包含一行。虽然Balance_Sheets
每个季度包含一行。因此,对于四分之一中的每一天,来自的数字Balance_Sheets
将是相同的。
这是我到目前为止的代码:
Dim Date1 As Date = dtpDateSelection.Value
Try
Dim cmd As OleDbCommand = New OleDbCommand("CREATE PROC Daily AS SELECT [H].[Ticker], [H].[Date], [H].[Close], [B].[Common_Stocks] FROM [Historical_Stock_Prices] AS [H] INNER JOIN [Balance_Sheets] AS [B] ON Int(Year([H].[Date])) = Int([B].[Year]) AND Int(Format([H].[Date],'Q')) = Int([B].[Period]) AND CStr([H].[Ticker]) = CStr([B].[Ticker]) WHERE CDate([H].[Date]) = #" & CDate(Date1) & "#", con)
cmd.ExecuteNonQuery()
Catch ex As Exception
Finally
Dim cmda As OleDbCommand = New OleDbCommand("DROP PROCEDURE Daily", con)
cmda.ExecuteNonQuery()
Dim cmdb As OleDbCommand = New OleDbCommand("CREATE PROC Daily AS SELECT [H].[Ticker], [H].[Date], [H].[Close], [B].[Common_Stocks] FROM [Historical_Stock_Prices] AS [H] INNER JOIN [Balance_Sheets] AS [B] ON Int(Year([H].[Date])) = Int([B].[Year]) AND Int(Format([H].[Date],'Q')) = Int([B].[Period]) AND CStr([H].[Ticker]) = CStr([B].[Ticker]) WHERE CDate([H].[Date]) = #" & CDate(Date1) & "#", con)
cmdb.ExecuteNonQuery()
End Try
此代码在该表中创建表和Daily
字段Ticker
、[Date]
和。但是代码不会将任何数据加载到表的行中。有什么想法为什么不呢?[Close]
Common_Stocks