Sunday, March 31, 2013

[SQL Server] Cursor in Stored Procedure

[SQL Server] Cursor in Stored Procedure


Cursor in Stored Procedure

Posted: 31 Mar 2013 12:53 AM PDT

Hi,I am a SQL newbie and need to update code in a Stored Procedure that has a cursor. Is it possible to have multiple queries in a cursor? Currently, we are checking for duplicates in a database table when importing an Excel upload file. Now, we also want to check for potential duplicates in an Excel upload file and if the Excel file record falls into an already exisiting date range (passing start and end dates). I do not need help with the queries, but just wanted to give a little background information. I need help to understand how to get three queries to work in a cursor and make a decision if duplicates are found.Can someone please provide sample code on how to place three queries in a cursor and/or provide a good reference? Basically, on a high level this is what I want to do:Run Qry 1 - check for duplicates in database tableRun Qry 2 - check for duplicates in fileRun Qry 3 - check to see if record already exists in specific date rangeif no duplicates, then "0" count of dupsif dup is found, than Count and error type descriptionThanks in advance, any help is much appreciated!

No comments:

Post a Comment

Search This Blog