question

hillb avatar image
hillb asked

Using a CSV file values to filter a SQL table

Good day All. Newbie here. Normally I use a WHERE column_x IN('1234', '5678','xxxx','yyyy') to filter records for a table, but in this case I have a CSV file containing 1000's of numbers and I was wondering if I could use the CSV directly in my query. The CSV file is just a column of numbers: 1234 5678 xxxx yyyy Is it possible to do a query where I look at the CSV file values to filter my table records? For example: SELECT * FROM Table_x WHERE column_x IN (values from the CSV file) Thank you!
csvfilter
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
ThomasRushton avatar image
ThomasRushton answered
In theory, yes. Something like: SELECT * FROM Table_x WHERE column_x IN ( SELECT csv.* FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', '', 'SELECT * FROM FileName.csv') csv ) ; Unfortunately, I've not got a machine handy to test this theory out...
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.