Question

SQL Server 2008 R2 supports CLR integration where a .NET module can be registered in the database and can be invoked through SQL stored procedures, functions, triggers. We are able to develop such .NET modules and integrate with SQL Server.

But we have a different requirement where it is required to intercept the SELECT queries send to SQL Server (from any SQL client) and invoke a .NET module and pass the query parameters (WHERE clause) to it.

For example if we have a table (VarInfo) in database having two columns VarID (string) and Value (float). Now suppose the table contains records for 100 variables with VarID: V001 to V100. But the Value column is empty for all records. The Value data is not stored in the database. If we have a SQL select query:

SELECT Value from VarInfo where VarID = 'V001'

then the SQL Server should invoke the .NET module and pass the VarID. The .NET module shall fetch the variable Value from some external source. It shall then return the Value back to SQL Server. The SQL Server should return that Value as query output/result.

Please let know about the feasibility of the above in SQL Server 2008 R2.

Thanks,

Was it helpful?

Solution

The closest you could get would be a CLR User-Defined Function - but the calling code needs to be aware that it's a UDF and pass the parameters slightly differently, like:

SELECT Value FROM dbo.CLRUDF('V001')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top