How to get Cursor's record count (Transact-SQL) ?
-
Dear all, Please advise how to get the record count of Cursor ?
DECLARE @vendor_cursor CURSOR FOR
SELECT BusinessEntityID, Name
FROM Purchasing.Vendor
WHERE PreferredVendorStatus = 1
ORDER BY BusinessEntityID;OPEN @vendor_cursor;
FETCH NEXT FROM @vendor_cursor
INTO @vendor_id, @vendor_name;Thanks and best regards
-
Dear all, Please advise how to get the record count of Cursor ?
DECLARE @vendor_cursor CURSOR FOR
SELECT BusinessEntityID, Name
FROM Purchasing.Vendor
WHERE PreferredVendorStatus = 1
ORDER BY BusinessEntityID;OPEN @vendor_cursor;
FETCH NEXT FROM @vendor_cursor
INTO @vendor_id, @vendor_name;Thanks and best regards
Do you need the count before, during or after the cursor has run. Before - use select count(*) with your cursor query During and After - set up a @Count variable and increment it within your cursor Set @Count = @Count + 1 This question shows a dramatic lack of thinking, the solution is so simple.
Never underestimate the power of human stupidity RAH
-
Dear all, Please advise how to get the record count of Cursor ?
DECLARE @vendor_cursor CURSOR FOR
SELECT BusinessEntityID, Name
FROM Purchasing.Vendor
WHERE PreferredVendorStatus = 1
ORDER BY BusinessEntityID;OPEN @vendor_cursor;
FETCH NEXT FROM @vendor_cursor
INTO @vendor_id, @vendor_name;Thanks and best regards
-
Excellent, there is another potentially useful keyword I have never used (or knew about).
Never underestimate the power of human stupidity RAH