SQL Server 2012 Import CSV into Mapped Columns

I am currently trying to import about 10,000 rows (from a CSV file) into an existing table.

I have only one column that I'm trying to import, but there is another column in my table called TypeId that I need to set to the static value ie 99E05902-1F68-4B1A-BC66-A143BFF19E37 .

So I need something like

 INSERT INTO TABLE ([Name], [TypeId]) Values (@Name (CSV value), "99E05902-1F68-4B1A-BC66-A143BFF19E37") 

Any examples would be great.

thanks

+4
source share
2 answers

As mentioned above, import the data into a temporary table and then paste this value into the actual table

 DECLARE @TempTable TABLE (Name nvarchar(max)) BULK INSERT @TempTable FROM 'C:\YourFilePath\file.csv' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) INSERT INTO TABLE ([Name], [TypeId]) Select Name,'99E05902-1F68-4B1A-BC66-A143BFF19E37' from @TempTable 
+5
source

If you are ready to use the tool for this, you can use the SQL Server Import and Export Wizard. You can run the SQL Server Import and Export Wizard from the Start menu, from SQL Server Management Studio, from SQL Server Data Tools (SSDT), or from the command line. With this tool, you can easily display the destination and source columns with ease. Later, if you want to update another column, you can use the code.

+2
source

All Articles