I have stocks data as .CSV (total 500 CSVs). My objective is to create a database with multiple tables named as 'A', 'B' where A & B refer to two different stocks. I've a table already loaded in database which contains a column with all 500 symbols.
I want to iterate over each row such that I can read CSV and create a table for that stock in my database. For example if the first row in the symbols table is 'A' then I want to create a table in my database named A by reading a csv file which would be named as '/path/A.csv'
All the tables have same structure. There are four columns "Date", "Open", "High", "Low", "Close", "Volume"
I've created a table for one stock. For example in case of stock A by using following code
create table A(
[Date] datetime2(7) NOT NULL,
[Open] float NULL,
High float NULL,
Low float NULL,
[close] float NULL,
Volume float NULL
)
BULK INSERT A
FROM 'D:\ASX\A.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '\n', --Use to shift the control to next row
TABLOCK
)
Since I can not manually change the name from A to B and to C till it reaches 500 therefore I would like to know how can I iterate 500 rows from my symbols table such that for each iteration my above code changes from A to B to C and so on.