MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 1st, 2004, 03:47 AM
sonasonia sonasonia is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 31 sonasonia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 40 sec
Reputation Power: 5
Question While loop in the Stored Procedure retrieves the first record alone...

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

Reply With Quote
  #2  
Old April 1st, 2004, 04:29 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,762 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 4 h 29 m 45 sec
Reputation Power: 37
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.

Reply With Quote
  #3  
Old April 1st, 2004, 07:09 PM
sonasonia sonasonia is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 31 sonasonia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 40 sec
Reputation Power: 5
Thumbs up

Hi swampBoogie,

Thanks for your reply. Your code solves my problem.

Regards,
SS

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > While loop in the Stored Procedure retrieves the first record alone...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway