Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Thursday, 13 April 2017

While Loop In SQL Server With Example

 asp.net, C#, for loop, procedure, SQL, table, while loop in sql     No comments   


Introduction
In this post we will learn how to looping in SQL server with while loop. Why we need while loop in sql and how can we use while loop with Stored Procedure.

Previous Updates
In previous articles we have learnt If Else and Case statement in SQL. What is Pivot table in SQl. Difference between Scope_Identity(), @@Identity and Ident_Current . Stuff and Replace in SQl. Temp table and table variable difference and when to use. Sequence in sql server with live situation example.Group By in SQL Server and use with Aggregate Functions 

When To Use
In SQL server many situations you did not know about how much time you need to execute the loop body. Using while loop you will be ensure that at a given condition your loop will iterate just like for loop in c#. Here instead of for loop you have to use while. There is no for loop in sql. 
You can use Break statement whenever you want to break out from while loop.

Practice
Write this type of query to use while loop with Stored Procedure or without Procedure.


DECLARE @loopDay INT
SET @loopDay = 5
WHILE @loopDay <= 10
BEGIN   
SET @loopDay = @loopDay + 1   
PRINT @loopDay
END

Output



  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write