Link to home
Start Free TrialLog in
Avatar of Zack
ZackFlag for Australia

asked on

Alternatives to Cursor function in SQL Script

Hi EE,

For the following script see attached is there a method of implementing this that doesn't use the Cursor function.

Any assistance is appreciated.

Thank you.
Datadump.txt
Avatar of HainKurt
HainKurt
Flag of Canada image

add

;

END;

Open in new window


to the end of script...

what is the exact issue here?

when I run it, it returns 4 resultset...
Avatar of Zack

ASKER

Hi HainKurt,

This question is more of a general inquiry for me as I have read multiple posts, saying you should avoid implementing queries that use cursors:

https://stackoverflow.com/questions/16711535/sql-server-avoiding-cursors

No actual issue with the script per say.

Thank you
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
but cursor is not nightmare, and here I see 5-10 maybe a couple of 100 records in the loop...
I dont see any big issue here... whats the problem with using cursor?
Avatar of Zack

ASKER

Thank you that gives me something to review when I get a chance, much appreciated.
Avatar of Zack

ASKER

Hi HainKurt,

For some reason, this Cursor function breaks on some our SQL servers I have got a feeling to got to do with the way the CLR is implemented, but I can't confirm.

Thank you.
if it fails with cursor, it will break with any other method as well...
this way, you can at least use try/except in the loop so you can control the process better...

if you can re-produce the issue, we can look at it later...