|
Posted by dba_222 on 08/16/06 05:20
Thanks for looking and responding.
Ok, This is part of what I wrote (as I posted).
I ran it in Query Analyser.
The symptom, as I mentioned, was not an error.
It was an infinite loop. (Has no one copied, and
pasted it???)
While @@fetch_status = 0
Print @customerid
Fetch all_cust
Into @customerid,
@Companyname,
@ContactName
End /* while */
The idea being, that the while is supposed to start at While,
and finish at End. Exactly what I found online.
Are you saying that a while loop can only handle one statement??
If not, what is the syntax to get it to execute all the code between
the While, and the End??? Do we give it a Begin???
These are some of the strange things I've found with Sql Server.
No semicolons to indicate the end of statement.
And no Begin or End to indicate the start and end of a block.
Much more difficult to read, and to write. In Oracle, you MUST
have an END LOOP statement, and semicolons.
You must also start and end the procedure with BEGIN and END.
Otherwise it won't even compile.
Steve Kass wrote:
> See inline comments. You are being sloppy, to but it bluntly.
> You can't expect programs to work if you miss copying a
> line, leave out begin-end pairs, or make other basic errors.
>
> Steve Kass
> Drew University
>
> <dba_222@yahoo.com> wrote in message news:1155688502.341846.321810@75g2000cwc.googlegroups.com...
> > Dear experts,
> >
> > Again, sorry to bother you again with such a seemingly dumb question,
> > but I'm having some really mysterious results here.
> >
> > ie.
> >
> > Create procedure the_test
> > As
> >
> >
> > Begin
> >
> > Select CustomerID
> >>From dbo.customers
> >
> > -----------------------------*/
> > Server: Msg 170, Level 15, State 1, Procedure the_test, Line 8
> > Line 8: Incorrect syntax near 'customers'.
> >
> > Just WHAT is the syntax please?????
> >
> >
>
> It looks to me like you are missing the keyword END.
>
>
> > -----------------------------------------
> >
> > Then, this started as trying to write a procedure with a cursor.
> > Open cursor, loop, print, end loop. End of story.
> >
> > This actually goes into an infinite loop!!!
> > Can anyone tell me what is wrong here?
> >
> >
> >
> >
> > Create procedure test2
> > As
> >
> > Declare all_cust cursor for
> > Select customerid,
> > Companyname,
> > ContactName
> >>From customers
> >
> >
> > Declare
> > @Customerid varchar(5),
> > @Companyname varchar(40),
> > @ContactName varchar(30)
> >
> >
> >
> > Begin
> >
> > Select count(*)
> >>From customers
> >
> >
> > Open all_cust
> >
> > Fetch all_cust
> > Into @customerid,
> > @Companyname,
> > @ContactName
> >
> >
> > While @@fetch_status = 0
> >
> > Print @customerid
>
>
> This is an infinite loop if anything is fetched. Printing @customerid
> will not change the value of @@fetch_status, so the statement
>
> WHILE @@fetch_status = 0
> PRINT @customerid
>
> will go forever.
>
>
>
> >
> >
> > Fetch all_cust
> > Into @customerid,
> > @Companyname,
> > @ContactName
> >
> > End /* while */
> >
> >
> > Close all_cust
> >
> > Deallocate all_cust
> >
> >
> >
> >
> >
> > Believe it or not, I'm just copying simple programs off the web,
> > including the Microsoft website, with slight modifications!!!!!!
> > Crazy!!!
> >
[Back to original message]
|