Hi Friends,
How to write Cursor used CLR Stored procedures in C#.
Cursor based CLR Stored procedure
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
jagadish patil13 reputationPosted May 29, 2009, 4:39 AM EDT
I am new to CLR SP's. Its very simple
Just write sp in sql server and test then just copy and paste like.
strQuery = @"DECLARE @SPName VARCHAR(255)
DECLARE SPNameCursor CURSOR FOR
SELECT STOREDPROCEDURENAME
FROM table
OPEN SPNameCursor
FETCH NEXT FROM SPNameCursor
INTO @SPName
WHILE @@FETCH_STATUS = 0
BEGIN
insert query
FETCH NEXT FROM SPNameCursor
INTO @SPName
END
CLOSE SPNameCursor
DEALLOCATE SPNameCursor";
then
List<Parameter> objParams = new List<Parameter>();
objParams.Add(new Parameter("@param1", val));
objParams.Add(new Parameter("@parame2", valDate));
int output = objSQLHelper.ExecuteNonQuery(strQuery,CommandType.Text, objParams);
return output;
Mohit Jain19 reputationPosted May 29, 2009, 6:05 AM EDT
The way you have created the CLR Stored Procedure is correct but Cursor are not recommended to be used. Instead of cursor I would suggest you to use Temporary Table or Table variable which provide good performance over cursor.