473,841 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I loop thru a result set?

How do I loop thru a result set Without using a curosr?
Jul 20 '05 #1
5 4044
[1]
select @key = min(key) from tab
while @key is not null begin
...
select @key = min(key) from tab where key > @key
end

[2]
Define a function which does your dirty work and returns a result value
(even dummy)
Then
select dbo.fn_dirtywor k(col1,col2,col 3,col4,...) from tab

[3]
Don't.

"Andrew Young" <at*******@yaho o.com> wrote in message
news:42******** *************** ***@posting.goo gle.com...
How do I loop thru a result set Without using a curosr?

Jul 20 '05 #2
On 28 Jun 2004 06:44:05 -0700, Andrew Young wrote:
How do I loop thru a result set Without using a curosr?


Hi Andrew,

Mischa already gave some suggestions. I'd have put number three first (and
repeated it several times).

Seriously: why do you want to loop through a result set? Can you describe
the business need you're trying to solve? Set-based solutions tend to be
better and quicker and most problems CAN be solved with set-based SQL.

On the other hand, if you really must (or want to) loop through a result
set, why not use a cursor? That's SQL's standard instrument for looping
through a result set. Of course, you can find other ways to do the same,
but they'll probably be less efficient than a cursor (which is already
very inefficient!)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #3
Andrew Young (at*******@yaho o.com) writes:
How do I loop thru a result set Without using a curosr?


I could a few more suggestions to Mischa's list, but I think I go with
his [3]. Then again, you should probably better clarify what your
real problem is. Maybe you are not iterating on the server, but in a
client?
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4
Here is my process:

I am pulling performance metrics for over a thousand servers, W2K,
W2K3, NT, RS6000, and AS400. This equates to about 50 to 100 million
rows of data in a 24 hour period. I have a SLA of 24 hours to provide
this data on a daily basis.

My process consists of pulling a comma delimited format file that I
'bulk insert', from a UNC path, into a temporary table. I then fire a
stored proc that reads thru the temp table and process the data.

The data file format is:
hostname,applic ation,applicati on_instance,par ameter,timesatm p,data_point

My database consists of a hostname table, application table, instance
table, parameter table, agregatted data table and a raw data table.

All have primary key and constraints except for raw data table. My
first stored proc determines the existence of the hostname, app,
inst,param, and if they don't exist it adds them to the respected
table and then dumps the raw into the raw data table with application
and parameter keys to be used later. This proc will fire and process
several time in a minute processing inbound data files.

Every six hours a aggregation proc fires and move the data from the
raw table into the agg table and then deletes the raw stuff.

I hope this explains my need for looping. Any advise would be much
appreciated.
Jul 20 '05 #5
Andrew Young (at*******@yaho o.com) writes:
My process consists of pulling a comma delimited format file that I
'bulk insert', from a UNC path, into a temporary table. I then fire a
stored proc that reads thru the temp table and process the data.

The data file format is:
hostname,applic ation,applicati on_instance,par ameter,timesatm p,data_point

My database consists of a hostname table, application table, instance
table, parameter table, agregatted data table and a raw data table.

All have primary key and constraints except for raw data table. My
first stored proc determines the existence of the hostname, app,
inst,param, and if they don't exist it adds them to the respected
table and then dumps the raw into the raw data table with application
and parameter keys to be used later. This proc will fire and process
several time in a minute processing inbound data files.

Every six hours a aggregation proc fires and move the data from the
raw table into the agg table and then deletes the raw stuff.

I hope this explains my need for looping.


Not really. That is, I don't really see where the loop comes in.

When you get that data in, you would do

INSERT hostnames (hostname)
SELECT DISTINCT hostname
FROM rawdata r
WHERE NOT EXISTS (SELECT *
FROM hostname h
WHERE r.hostname = h.hostname)

and the similar for the other tables.

The aggregation should be possible to carry out with set-based statements.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6264
by: Jeremy Langworthy | last post by:
Hi I have a dynamicly generated form (well the elements are at least) that looks something like this: while( not end of returned records): <input name="plan_id" type="checkbox" id="" value="<?= $row_plans->planid ?>">
3
5225
by: brett | last post by:
Using DOM in IE, how can I loop through FORMs and access FORM elements in a specific form? For example, www.hotmail.com has about 13 forms. I believe the one displayed is dependent on the URL. If I want to access the submit button of the visible form, which is usually the last one, how is that done? Currently, I look for type=submit using DOM but it doesn't find anything and only loops through the first FORM elements. Sorry if this...
2
1781
by: sparks | last post by:
I was going to loop thru the tables and change some properties. 10 <<<<<< prp.value --prp.name = Type False <<<<prp.value --prp.name = allow zero length 10 <<<<<< prp.value --prp.name = Type True <<<<prp.value --prp.name = allow zero length 10 <<<<<< prp.value --prp.name = Type True <<<<prp.value --prp.name = allow zero length 10 <<<<<< prp.value --prp.name = Type True <<<<prp.value --prp.name = allow zero length 4 <<<<<< prp.value...
3
6397
by: Jim Hernandez | last post by:
This has set me back a couple of days now and I could really use some help or at least a shove in the right direction. What I'm trying to do is list reviews in a database on a page, by artist (byartist.php). The first step is pulling each artist and listing them alphabetically. If the artist has more than one album reviewed, they should still only show up once, so I need to check each row of the recordset, and check the artistname...
2
5073
by: ckerns | last post by:
I have a page with a bunch of drop down boxes. They are named: MonEquipAMWk1 MonEquipPMWk1 thru FriEquipAMWk1 FriEquipPMWk1
16
6329
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataAdapter. For every record in tblA where colB = 'abc', I want to update the value in colA. In VB6, using ADO I can loop thru the recordset,set the values of colA and call the Update method. How can I do this in VB.NET and SqlDataAdapter ? Thank you. m_cmdSQL = New SqlClient.SqlCommand With m_cmdSQL .Connection = adoCon
3
2712
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Here is my loop and it runs fine: ---------------------------------------------------- sSQL = "SELECT * FROM STORE_ITEMS" Set DataRec = DB.execute(sSQL) if not DataRec.EOF then do while not DataRec.EOF SKU = trim (DataRec("SKU")) ITEM_ID = trim(DataRec("ITEM_ID")) ...
2
2997
by: deggler | last post by:
hi, i'd need to run a while ($row = mysql_fetch_array($result)) loop thru the whole table and then one more time. this last time the $row variable shouldn't get any values. i just need everything in the loop be done one more time. Thank u very much for your help deggler
0
9864
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10302
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7846
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5691
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4081
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.