|
-
Nov 6th, 2006, 12:28 AM
#1
Thread Starter
Hyperactive Member
sql server while loop...
how to use while loop to fetch record in sql server without using cursor...
-
Nov 6th, 2006, 12:46 AM
#2
Re: sql server while loop...
Can you explain a little more of what your trying to do?
Create a progressbar to display the recordset population during a long rs.open method call?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 6th, 2006, 01:09 AM
#3
Re: sql server while loop...
I think that using a Cursor is the only way to Fetch records in SQl Server, but maybe the question should be.. do you really need to Fetch records? What are you trying to do?
-
Nov 6th, 2006, 01:13 AM
#4
Re: sql server while loop...
I thought about the terminology used too as Fetch is a cursor method call.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 6th, 2006, 01:58 AM
#5
Thread Starter
Hyperactive Member
Re: sql server while loop...
i have storeprocedure in which
i need to open a table and retrive some records and update some values in it...
using cursor im able to do so...
but in many sites it is mentioned that using cursor will use more system resources...
so is there any other possibilities fetching records without using cursor...
-
Nov 6th, 2006, 02:26 AM
#6
Re: sql server while loop...
Use an Update query.
Update TableName
Set Field1 = Value, Field2 = Value2...
Where....
-
Nov 6th, 2006, 08:01 AM
#7
Re: sql server while loop...
As BRUCEVDE said - use an UPDATE query. Almost everything can be done in a "single" set-based logic update...
But if you cannot do it in an UPDATE, another way is to loop through a table and process rows - I do this in STORED PROCEDURES all the time
btw - this should have been posted in the DATABASE DEVELOPMENT section of this forum...
Now assuming that your "table" has an integer primary key and you are going to process them in order from first through last...
Code:
Declare @PriKey Int
Set @PriKey=(Select Min(ColumnA) From SomeTable)
While @PriKey is not null
Begin
.
.
... process your row here...
.
.
Set @PriKey=(Select Min(ColumnA) From SomeTable Where ColumnA>@PriKey)
End
This code will loop through rows in a table - one at a time. It will do this without incurring CURSOR-type memory issues...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|