SQL Server File Operations?

2019-03-03 11:30发布

问题:

Using SQL Server 2005: How can I read a file into a SPROC using T-SQL?

So, imagine I have a CSV file like so:

ID,OtherUselessData
1,asdf
2,asdf
3,asdf

etc...

I basically want to do this:

Select * from mytable where id in (select id from txtFile)

回答1:

Consider using OPENROWSET function to open/parse you CSV file and use it as a 'row source' (i.e. like a table)



回答2:

here are some examples: http://www.simple-talk.com/sql/t-sql-programming/reading-and-writing-files-in-sql-server-using-t-sql/