Levels & do / for loop in MSSQL procedure..

  • Hi

    Can i use below procedure in MSSQL2000. Will i work. If not, could you please let me know how do i convert this into MSSQL2000 comapatible code. I dont think MSSQL2000 supports Level: and for & do loop inside procedur / cursor.

    CREATE PROCEDURE TopCustomerValue2( OUT TopCompany CHAR(36),OUT TopValue INT )

         BEGIN

             -- Initialize the TopValue variable

             SET TopValue = 0;

             -- Do the For Loop

         CompanyLoop:

             FOR CompanyFor AS ThisCompany CURSOR

                 FOR

                 SELECT  company_name AS ThisValue FROM customer

             DO

             IF ThisValue > TopValue THEN

                 SET TopCompany = ThisName;

                 SET TopValue = ThisValue;

             END IF;

         END FOR CompanyLoop;

      END

    Please help me on this. I am unable to get the help from online books. Hope you will have solution..

    Regds.

    ~ SHAM ~

  • USE pubs

    SET ROWCOUNT 10

    SELECT * FROM authors

    ORDER BY  au_lname, au_id

    SET ROWCOUNT 0

    SET ROWCOUNT 10 sets number of lines to return to 10.  It can be set using a variable.

    The last line resets the numer of lines to return to unlimited... don't forget that one

  • Don't know what coding that is but my guess for a solution would be

    CREATE PROCEDURE TopCustomerValue2

      @TopCompany CHAR(36) OUTPUT,

      TopValue INT OUTPUT)

    AS

    SELECT TOP 1 @TopCompany = company_name, @TopValue = value

    FROM [customer]

    ORDER BY [value] DESC

    GO

    DECLARE @Company CHAR(36), @Value INT

    EXECUTE TopCustomerValue2 @Company OUTPUT, @Value OUTPUT

    SELECT @Company, @Value

    Far away is close at hand in the images of elsewhere.
    Anon.

  • My guess is that it looks like Oracle but I ain't ever coded in Oracle so I'm not sure of that either.

     

     

    Maybe if you could give us the requirements of the query / procedure, then we would be able to give you the correct solution to your problem without having any of us guessing on what you need.

Viewing 4 posts - 1 through 3 (of 3 total)

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