January 25, 2017 at 8:00 am
Hey, I have a real life problem where I received some files initially and based on those files, history was generated like below table and was pushed to production:
TableName - SymbolHistory_tbl
ColumnNames - SymbolTypeID INT, SymbolValue varchar, FromDate datetime. ToDate Datetime
After few months we received another file which has only the data which was missing as well as some repeated data in the first file (rows missing in millions). I generated the history only by using this file-
TableName - SymbolHistory_tbl_GapData
ColumnNames - SymbolTypeID INT, SymbolValue varchar, FromDate datetime. ToDate Datetime
Now I am facing huge challenge in merging these SymbolHistory_tbl_GapData - into - SymbolHistory_tbl.
There are huge number of records and nothing can be done manually.
Please help or suggest any link which can help me solve this.
Thanks
January 25, 2017 at 8:12 am
INSERT INTO SymbolHistory_tbl (
SymbolTypeID
, SymbolValue
, FromDate
, ToDate
)
SELECT
SymbolTypeID
, SymbolValue
, FromDate
, ToDate
FROM SymbolHistory_tbl_GapData
John
January 25, 2017 at 8:17 am
John Mitchell-245523 - Wednesday, January 25, 2017 8:12 AMI'm almost certainly missing something here, but could it be as simple as this?
INSERT INTO SymbolHistory_tbl (
SymbolTypeID
, SymbolValue
, FromDate
, ToDate
)
SELECT
SymbolTypeID
, SymbolValue
, FromDate
, ToDate
FROM SymbolHistory_tbl_GapDataJohn
You missed the fact that these are timeseries tables (FromDate, toDate columns). They should not overlap. after merging there should be not duplicate for any date for any SymbolTypeiD. Thanks
January 25, 2017 at 8:22 am
If a simple insert won't work, we'll need a lot more information starting with sample data and expected results as outlined in the first link in my signature.
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
January 25, 2017 at 8:24 am
John
January 25, 2017 at 9:54 am
chandrakant_gaurav - Wednesday, January 25, 2017 8:00 AMHey, I have a real life problem where I received some files initially and based on those files, history was generated like below table and was pushed to production:
TableName - SymbolHistory_tbl
ColumnNames - SymbolTypeID INT, SymbolValue varchar, FromDate datetime. ToDate DatetimeAfter few months we received another file which has only the data which was missing as well as some repeated data in the first file (rows missing in millions). I generated the history only by using this file-
TableName - SymbolHistory_tbl_GapData
ColumnNames - SymbolTypeID INT, SymbolValue varchar, FromDate datetime. ToDate DatetimeNow I am facing huge challenge in merging these SymbolHistory_tbl_GapData - into - SymbolHistory_tbl.
There are huge number of records and nothing can be done manually.
Please help or suggest any link which can help me solve this.Thanks
Try:
MERGE SymbolHistory_tbl TargetTab
USING SymbolHistory_tbl_GapData SourceTab
ON TargetTab.SymbolTypeID = SourceTab.SymbolTypeID
AND TargetTab.FromDate= SourceTab.FromDate
AND TargetTab.ToDate= SourceTab.ToDate
WHEN MATCHED THEN UPDATE SET SymbolValue=SourceTab.SymbolValue
WHEN NOT MATCHE THEN INSERT (SymbolTypeID, SymbolValue, FromDate, ToDate)
VALUES (SourceTab.SymbolTypeID, SourceTab.SymbolValue, SourceTab.FromDate, SourceTab.ToDate);
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply