views:

76

answers:

2

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<br/>
1,asdf<br/>
2,asdf<br/>
3,asdf<br/>

etc...

I basically want to do this:

Select * from mytable where id in (select id from txtFile)
+2  A: 

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

AlexS
+1  A: 

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

KM
+1 excellent stuff as always on www.simple-talk.com !!
marc_s
ya, I saw that already and will use it if needbe, but that's a custom sproc that he wrote and I thought there was a built-in sqlserver way to do this?
Scott
you should at least look at that procedure's code, there is no need to build your own wheel...
KM