Sql-server – Select IDs according to CSV file

csvexportsql server

I have a CSV file with IDs of rows. I want to use that to make a SELECT statement selecting the IDs within that CSV file.

There is 1 million rows and I want to select about 95,000 of those.

I want to SELECT and import these rows to another SQL Server database using the SQL Server Import and Export Wizard.

I'm using MSSQL 2005 with SQL Server Management Console.

Best Answer

Probably best to:

  1. Import the entire CSV to a table using Import and Export Wizard.
  2. Run the query to pull the data you want from the table.
  3. Use the Import and Export Wizard to import to the other database.
  4. Clean up the CSV import, probably by truncating or deleting the table.

Unless you want to use SSIS? Then you can design a package to do it easily without importing the whole file directly.