- Is it possible to make a big project in C# (lots of functions), then,
- Create CLR Assembly for it, then,
- In SQL Server IN A STORED PROC, call a function that is in the assembly,
The table (which I would pass to ASSEMBLY) is computed in other stored proc...
- If so, What would be the steps?
I am thinking something like this.
-- I have a stored proc that gets a table, let it be myStoredProcTable
--FIST ENABLE DATA ACCESS
EXEC sp_serveroption 'TheServerName', 'DATA ACCESS', TRUE
--main.sql calls yStoredProcTable.sql and the calls functionAssembly
SELECT *
INTO #tmpTable
FROM OPENQUERY(SERVERNAME, 'EXEC test.dbo.myStoredProcTable 1')
-- pass the table to assembly
-- how would i pass the table to assembly code?, Is this POSSIBLE?
EXEC functionAssembly #tmpTable
------------------------------------------edit
Following @faester
answer:
- How could I use XML in the code, I suggested to use the numberTOstring
thing, but I guess XML
option is the best here...
Again, I really do this, even if is not the best choice...
Use the SQL CLR to perform the exact function you described.
It is possible. (But read the comments).
Yes you can register assemblies, but it is rarely a good idea due to performance issues.
But if you make complex numeric calculations or similar operations on scalar values it can give you a lot of flexibility. But the problem remains that SQL is natively set oriented which C# isn't, so you will easily run into mismatches.
You should also be aware that you can only import static members on static classes.
But an example This class - which intentionally doesn't have a namespace since it seems to be impossible to import classes in a namespace.
It takes some SQL to get the server ready and you probably need to be admin.
AGAIN: You really should be confident that you need this, it is rarely a good idea! (I have used it once for email validation making dns lookups etc, but that was on a system where all business logics was written in SQL. And that is bad!)
Some useful references:
http://msdn.microsoft.com/en-us/library/ms189524.aspx
http://www.codeproject.com/KB/database/CLR_in_Sql_Server_2005.aspx