0

I am doing a project using sql cursors, for one cursor i want to loop through a dataset of Company ids.

How would you use logic such as

  1. Tables without CompanyID need all data copying.
  2. Always copy data where CompanyID = 0

How would you perform this is a while loop of a cursor.

I have been looking at this tutorial

http://examplesql.com/sqlserver-transact-t-sql/how-to-loop-using-sql-server-cursor-fetch-fast_forward/

user2520671
  • 83
  • 3
  • 13

1 Answers1

2

For one it's always recommended in all cases to absolutely avoid the use of cursors. They are known to experience very poor performance issues and 95% of the time it's possible to perform the necessary function with set-based logic.

To solve this particular problem using psuedo would look something like this:

INSERT INTO DestinationTable
SELECT CompanyID, SomeDataColumn
FROM SourceTable
WHERE ISNULL(CompanyID, 0) = 0
David
  • 1,591
  • 1
  • 10
  • 22
  • It is not me choosing the cursor approach my boss has told me to use them, thanks for your solution it looks like what i need – user2520671 Oct 28 '13 at 16:17