Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Loop through Table Records

 
   Database Help (Home) -> Programming RSS
Next:  cursor/barcode  
Author Message
scott

External


Since: Jan 19, 2008
Posts: 22



(Msg. 1) Posted: Wed Apr 16, 2008 7:20 pm
Post subject: Loop through Table Records
Archived from groups: microsoft>public>sqlserver>programming (more info?)

I'm working on a script that creates a temp table called #tmpList.

How can Loop through the records of #tmpList? So far in my using SQL, I've
always written SQL statements to just return records and I did my looping
with VB. I need to be able to loop through the temp table and perform a
function on each email name that exists in my temp table.


EXAMPLE:

-- #tmpList Table shown below

myEmails
--------------------
user1 DeleteThis @cnn.com
user2 DeleteThis @cnn.com
user3 DeleteThis @cnn.com

 >> Stay informed about: Loop through Table Records 
Back to top
Login to vote
Stuart Ainsworth

External


Since: Jan 10, 2008
Posts: 91



(Msg. 2) Posted: Wed Apr 16, 2008 7:20 pm
Post subject: Re: Loop through Table Records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Apr 16, 8:20 pm, "scott" wrote:
> I'm working on a script that creates a temp table called #tmpList.
>
> How can Loop through the records of #tmpList? So far in my using SQL, I've
> always written SQL statements to just return records and I did my looping
> with VB. I need to be able to loop through the temp table and perform a
> function on each email name that exists in my temp table.
>
> EXAMPLE:
>
> -- #tmpList Table shown below
>
> myEmails
> --------------------
> us....DeleteThis@cnn.com
> us....DeleteThis@cnn.com
> us....DeleteThis@cnn.com

A general rule of thumb is that before you think about looping in SQL,
be sure that you absolutely have to do it this way. Although you can
use a CURSOR (hint: look up cursors in the Books Online for usage),
they're usually not the best solution to a problem.

Does your function have to perform on one item at a time? What does
the function do? Does it really belong at the data layer, or should
you be returning the data set to a client that iterates through a
collection, performing a function at that level.

Stu

 >> Stay informed about: Loop through Table Records 
Back to top
Login to vote
scott

External


Since: Jan 19, 2008
Posts: 22



(Msg. 3) Posted: Wed Apr 16, 2008 8:49 pm
Post subject: Re: Loop through Table Records [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

The function is a smtp email function that only sends 1 email at a time. So
yes, each record or item needs to be processed one at a time.


"Stuart Ainsworth" wrote in message

On Apr 16, 8:20 pm, "scott" wrote:
> I'm working on a script that creates a temp table called #tmpList.
>
> How can Loop through the records of #tmpList? So far in my using SQL, I've
> always written SQL statements to just return records and I did my looping
> with VB. I need to be able to loop through the temp table and perform a
> function on each email name that exists in my temp table.
>
> EXAMPLE:
>
> -- #tmpList Table shown below
>
> myEmails
> --------------------
> us....RemoveThis@cnn.com
> us....RemoveThis@cnn.com
> us....RemoveThis@cnn.com

A general rule of thumb is that before you think about looping in SQL,
be sure that you absolutely have to do it this way. Although you can
use a CURSOR (hint: look up cursors in the Books Online for usage),
they're usually not the best solution to a problem.

Does your function have to perform on one item at a time? What does
the function do? Does it really belong at the data layer, or should
you be returning the data set to a client that iterates through a
collection, performing a function at that level.

Stu
 >> Stay informed about: Loop through Table Records 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Loop through Records and update individual records - Hi, I have the following T-SQL script but I'm not able to convert the logic to T-SQL syntax correctly. I'm stucked with the syntax to do looping What I have in mind is to only UPDATE individual records that have the condition of timebased of "...

How to loop through records - I have @WeekIDFrom and @WeekIDTo as input parameters in a stored procedure. I need to loop through each value between @WeekIDFrom and @WeekIDTo and insert the value into a table, like this: INSERT INTO tblSchedule (WeekID) VALUES (@WeekID) Can someone...

Loop through records to Update data? - I am trying to update a table, based on what was in the previous record. Let me try to explain better - the code is at the end. In my table, I have projects, activities, credit amount, debit amount, and starting balance. Each project can have several....

Infinite loop when fetching records in cursor -

How to loop a temp table? - I have a statement in my stored procedure that has the following as an example - INSERT #TempTableOutput EXEC (@select + @from + @where + @order) How could I then loop through the records of #TempTableOutput to update some blank fields that were..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]