Sometimes procedural programming is absolutely unavoidable when processing data.
I am currently working on optimizing some legacy code. It uses a cursor, 63 pairs of IF
/ELSE
statements and BEGIN
/END
's etc. I had hoped to reverse engineer the cursor and make it a procedural process. Now I'm at the end of decoding the algorithm and I realize . . . ooops...it has to be procedural because each choice made on a record depends on the outcome of the process on all the preceding records.
So now I'm torn...there are other choices for mixing procedural code in with SQL Server processing (CLR SPs, UDF's etc.). I'm a big believer in using the right tool for the job, so I'm leaning towards making a .NET CLR SP for this. But it would be faster and "easier" to just simplify the cursor a bit, but still keep the cursor.
What do you all think? Now that we have .NET modules accessible from withing SQL Server, is it ever appropriate anymore to use cursors (which in my opion were a kludge/work around to begin with).