I am currently trying to use a bulk insert from a temporary table with information from a CSV and then add the details of this table into a current one (without having to drop the proper table as it contains information already) I have currently got this:
Please ignore the table being dropped at the start, this was for testing purposes. Now I am kind of at a stump as to what I would need to do next, would I simply want to use an update table and state the column names and use a FROM statement.
DROP TABLE #Currencies
CREATE TABLE #Currencies(
suffix nvarchar(50) NULL,
name nvarchar(50) NULL,
iso nvarchar(50) NULL)
GO
BULK INSERT #Currencies
FROM 'C:\Documents and Settings\ntaylor\Desktop\Currencies.csv'
WITH(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n')
GO
ALTER TABLE #Currencies
ADD version_number int NOT NULL default 1,
[precision] int NULL,
cur_id [uniqueidentifier] NOT NULL default newid(),
exchange_rate decimal(19,5) NULL,
[default] bit NULL
GO
UPDATE #Currencies
SET [precision] = 2, exchange_rate = 1, [default] = 0
ALTER TABLE tbl_ecom_currency
ALTER COLUMN suffix nvarchar(50)
INSERT INTO tbl_ecom_currency (suffix, name, iso, version_number, [precision], cur_id, exchange_rate, [default])
SELECT suffix, name, iso, version_number, [precision], cur_id, exchange_rate, [default]
FROM #Currencies
After executing this Query I seem to have the issue that it’s creating all of the rows within the table but they don’t seem to be proper rows as they are not there when i click edit top 200 rows however it seems to work when I choose to select top 1000 rows, but it creates them every single time so I have 1000+ rows now opposed to 150+
I have managed to find a working method for this, using the following code I was able to execute it fine.