Solved

Loops in SQL

Posted on 2011-09-08
2
207 Views
Last Modified: 2012-05-12
Hello,

I am still trying to grasp some of the topics in SQL, and am wondering what loops are used for? I know how to construct a loop, but I just don't know in what case you would use one. If you could give me some real life examples with a description that would be great. Thanks.
0
Comment
Question by:erp1022
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 300 total points
ID: 36505520
Generally loops should be avoid in SQL.  Database theory is based in set mathematics, thus SQL should use set based solutions as much as possible.  That being said the times to use loops are when it's necessary to execute thing row by row.  A common one that I run into is when I have a table of data to process and the stored procedure that processes the data only accepts single values, basically one record.  I would loop through my table and execute the procedure many times.  Not the most efficient way to do it.  Given more time, I would rather rewrite the called stored procedure to accept a table parameter or XML and process all the rows at once.  That's not always possible though.

Greg

0
 

Author Closing Comment

by:erp1022
ID: 36505651
Thanks!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question