November 12, 2011 at 4:12 am
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!!
November 12, 2011 at 4:27 am
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.
November 12, 2011 at 4:30 am
THEN WHAT IS ROLE OF LOOP KEYWORD IN SQL...
November 12, 2011 at 4:42 am
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)
November 12, 2011 at 4:50 am
Loop Keyword Not Found in the given link..
there is no reserved kyword like LOOP...
November 12, 2011 at 4:53 am
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.
November 12, 2011 at 5:02 am
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...;-)
November 12, 2011 at 5:10 am
shubham.saxena67 (11/12/2011)
As u know that each keyword that is reserved shows with blue colorand 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
November 12, 2011 at 5:15 am
:crazy: ... That is what I want to convey...
Plz send me sample sql statement about this...
November 12, 2011 at 5:17 am
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.
November 12, 2011 at 5:19 am
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...
November 12, 2011 at 5:19 am
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
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply