Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Collapse LoopingLooping
Expand Error HandlingError Handling
Expand v.IMP Queriesv.IMP Queries
Expand XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

While..Break

 
      DECLARE     @ctr    TINYINT
      DECLARE     @sum    TINYINT

      SET @ctr    = 0
      SET @sum    = 0

      WHILE   @ctr < 5
      BEGIN
          SET @ctr = @ctr + 1
          SET @sum = @sum + @ctr
          IF  @ctr > 5        BREAK
      END

      SELECT  @sum  as  'Sum of First 5 Natural No.s'