I want a basic update procedure that updates a temporary table and orders it by PrimID and myDates, and then updates a permanent table. The data structure looks like this:
PrimID MyDates Price
1 1/1/2014 1
1 1/2/2014 2
2 1/1/2014 11
2 1/2/2014 12
3 1/1/2014 21
3 1/2/2014 22
The csv file looks exactly the same, just without the header column names. Here is my code thus far:
CREATE Table #TempT
(
PrimID Int,
myDate Date,
myPrice Float
);
BULK
INSERT #TempT
FROM 'D:\MyWerk\SQL\TEST_dPrice_Data.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
Select * From #TempT
Order by PrimID,myDate
Drop Table #TempT
What is missing, and what I am trying to get to, is the UPDATE of the permanent table with the ordered #TempT, ordered by PrimID and then myDates(oldest to lastest). If there are PrimID & myDates data in the csv that are already in the permanent table, I want to overwrite the data in the permanent file as well. Also, is there a better way to get the data in chronological order, other than using order by?
I use SQL Server 2012.
Much appreciated.
mydateandmypricevalues based on theprimid, but only on price ifprimidandmydateare in both tables?