Solved

SQLCODE

Posted on 1998-12-08
7
847 Views
Last Modified: 2008-03-04
What is wrong with this syntax? I've written this in Query Analyzer (7.0 beta) and when I attempt to run it I get an "Incorrect syntax near '='." error.

--My Code
declare cProcList cursor for
      select name from sysobjects
            where xtype = 'P'
                  and name > 'du'
            order by name
open cProcList
while (SQLCODE == 0)
(
      fetch cProcList
)
close cProcList
0
Comment
Question by:bjames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:spiridonov
ID: 1092144
>while (SQLCODE == 0)
Why do you have two 'equal' signs?
0
 

Author Comment

by:bjames
ID: 1092145
That is the way the example until FETCH in Books On-Line shows it. And when I change the == to a single = I get another error:

Incorrect syntax near the keyword 'fetch'.

0
 
LVL 2

Expert Comment

by:tschill120198
ID: 1092146
I don't have the SQL 7 BOL with me right now, but the parenthesis around the fetch look suspicious.  I've not spent a lot of time with SQL 7, so maybe they've added that syntax... try begin/end instead:

while (SQLCODE = 0)
begin
    fetch cProcList
end
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bjames
ID: 1092147
That gives me a new error.

Invalid column name 'SQLCODE'.
0
 
LVL 2

Accepted Solution

by:
tschill120198 earned 50 total points
ID: 1092148
Let's back up a bit... what is it you are trying to do?  

Looks to me like you want to cursor through all sprocs and do something with each... try this:

    declare @sprocname varchar(128)
    declare cProcList cursor for
        select  name
        from    sysobjects
        where   xtype = 'p'
        and     name > 'du'
        order by name
    open cProcList
    while (1=1) begin
        fetch next from cProcList into @sprocname
        if @@fetch_status = -1 break
        if @@fetch_status = -2 continue
        if @@fetch_status <> 0 break
        -- do whatever here with each sproc
        print @sprocname
    end
    close cProcList



0
 

Author Comment

by:bjames
ID: 1092149
Thanks. It works great. Sorry for the trouble. I'm still new to SQL Server.
0
 
LVL 2

Expert Comment

by:tschill120198
ID: 1092150
No trouble at all.  Enjoy SQL 7!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question