Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Loops in SQL

Posted on 2011-09-08
2
Medium Priority
?
212 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 1200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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