0

I would like to create a user defined function / store procedure or another SQL mechanism that when passed a filename will read the file contents into a variable for later processing. The mechanism must work within a transaction.

My plan was to use a user defined function however the OPENROWSET function doesn't allow me to pass a variable in as the filename so I need to execute it within a "sp_executesql" statement and the function become non-deterministic.

Are the any workarounds I can user to get around non-deterministic function?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1683456
  • 91
  • 1
  • 2
  • 7

2 Answers2

0

Yes, you can use so called "CLR Functions" functions that invoked by SQL Server from DLL provided by developer. See details on http://technet.microsoft.com/en-us/library/ms189876.aspx

But note, that deal with file from server-side is not scale-able solution with big security issues.

Dewfy
  • 23,277
  • 13
  • 73
  • 121
0

The CLR option will get you exactly what you want (see @Dewfy's comments) but another option is to do a bulk insert, if your data allows for it. It is not scale-able either, issues with multiple users doing this at once, but maybe your situation allows for this??

Steve
  • 5,585
  • 2
  • 18
  • 32