|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Hi,
Below I have given the Stored procedure. When I execute the SP I expect 8 rows to be returned (since tbl_loginaccount has 8 rows) but this returns only the first row. I'm not very sure where I go wrong. If anyone can spot out the problem it will be great. CREATE PROCEDURE dbo.GetVal AS Declare @v varchar(8000) Declare @v2 varchar(20) DECLARE authors_cursor CURSOR FOR SELECT HandlingCountry , EmployeeID FROM tbl_loginaccount OPEN authors_cursor -- Perform the first fetch. FETCH NEXT FROM authors_cursor into @v,@v2 -- Check @@FETCH_STATUS to see if there are any more rows to fetch. WHILE @@FETCH_STATUS =0 BEGIN Select @v as HandlingCountry, @v2 as Username -- This is executed as long as the previous fetch succeeds. FETCH NEXT FROM authors_cursor into @v,@v2 END CLOSE authors_cursor DEALLOCATE authors_cursor GO |
|
#2
|
|||
|
|||
|
What happens is that you get different result sets, each containing one row.
Code:
CREATE PROCEDURE dbo.GetVal AS SELECT HandlingCountry , EmployeeID FROM tbl_loginaccount GO That is all you need. |
|
#3
|
|||
|
|||
|
Hi swampBoogie,
Thanks for your reply. Your code solves my problem. Regards, SS |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > While loop in the Stored Procedure retrieves the first record alone... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|