Loop Keyword in SQL-BY SHUBHAM@INVENTIVE INFORMATICS BAREILLy

  • Dear Friends ,

    I need to know how to use 'Loop' Keyword in sql satement

    Plz send a sample query ..Can we replace my while loop with 'Loop'

    keyword

    for example:

    declare @var int

    set @var=0

    while (@var!=5)

    begin

    Print('Loop Executed ')

    set @var=@var+1

    end

    how above statement can be replaced by LOOP keyword with FOR in SQL SATEMENTS...

    thanks!!

  • WHILE Boolean_expression

    { sql_statement | statement_block | BREAK | CONTINUE }

    WHILE (Transact-SQL)

    http://msdn.microsoft.com/en-us/library/ms178642.aspx

    Control-of-Flow Language (Transact-SQL)

    http://msdn.microsoft.com/en-us/library/ms174290.aspx

    There is no FOR loop in SQL Server.

  • THEN WHAT IS ROLE OF LOOP KEYWORD IN SQL...

  • shubham.saxena67 (11/12/2011)


    THEN WHAT IS ROLE OF LOOP KEYWORD IN SQL...

    Do you find any LOOP keyword here?

    Reserved Keywords (Transact-SQL)

    http://msdn.microsoft.com/en-us/library/ms189822.aspx

  • Loop Keyword Not Found in the given link..

    there is no reserved kyword like LOOP...

  • shubham.saxena67 (11/12/2011)


    Loop Keyword Not Found in the given link..

    there is no reserved kyword like LOOP...

    ha ha :-D... That is what I want to convey. It's not available in SQL Server.

  • Dear Mr. Happy,

    As u know that each keyword that is reserved shows with blue color

    and LOOP also shows with Blue color within query analyzer..that's why i am

    asking..but u do not try more..i got so much help form your side..

    thank u very very much...;-)

  • shubham.saxena67 (11/12/2011)


    As u know that each keyword that is reserved shows with blue color

    and LOOP also shows with Blue color within query analyzer..that's why i am

    asking.

    It is a keyword, but it is not a control flow statement (as IF and WHILE are). It's part of a query hint - LOOP JOIN.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • :crazy: ... That is what I want to convey...

    Plz send me sample sql statement about this...

  • Is this theorical only?

    Or do you have a task that you need to accomplish?

    Loops in sql are very very rarely used outside of server administration work.

  • shubham.saxena67 (11/12/2011)


    Dear Mr. Happy,

    As u know that each keyword that is reserved shows with blue color

    and LOOP also shows with Blue color within query analyzer..that's why i am

    asking..but u do not try more..i got so much help form your side..

    thank u very very much...;-)

    It’s very encouraging...

  • shubham.saxena67 (11/12/2011)


    :crazy: ... That is what I want to convey...

    Plz send me sample sql statement about this...

    The LOOP keyword has nothing to do with control flow loops. It's a query hint.

    What are you trying to do and why are you convinced that you want to loop (which, btw, is done with the WHILE keyword in SQL, as per your original code)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply