I am building up a dataset from SQL server – a stored procedure that returns a dataset. It takes several passes to manipulate the data how I need it. I did this previously in a T-SQL stored proc, but it is getting too complex, so I am moving to SQL CLR. In T-SQL, i had several table variables
declare @theData as ( col1 int, .... )
and I ended with a select statement that joined these tables. In SQL CLR, I could instead have a list of objects:
List<MyObject> theData = new List<MyObject>();
The question: Would it be better practice to use the table variables or a .NET collection of objects?
I could see you’re not building up things IN MEMORY using table variables, rather the work is being done on the SQL server. Syntactically it wouldn’t matter to me because I could do “batch update” statements using Linq or SQL.
If you can use the table variables, CTEs, etc to return the data you need I would stick with that. Using CLR is great if you need to utilize managed code features (think object features) but can be overkill if you don’t really need to use it. You can look at this for an overview: http://msdn.microsoft.com/en-us/library/ms131045.aspx.