Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007

    Unanswered: Declaring variables for later use


    This works

    isql> declare @i int
    isql> select @i = 1
    isql> go
    (1 row affected)

    But this doesn't

    isql> declare @i int
    isql> go
    isql> select @i = 1
    isql> go
    Msg 137, Level 15, State 1:
    Server 'DSGPCPOET01', Line 1:
    Must declare variable '@i'.

    I have tried it inside a transaction, but same thing.
    Even though the connection is not closed between these statements, Sybase seems to "forget" that I have declared the variable.

    Mostly just curious.... Can anyone explain why this happens.


  2. #2
    Join Date
    May 2005
    South Africa
    Provided Answers: 1
    Transact-SQL® User's Guide
    Chapter 14 Using Batches and Control-of-Flow Language


    A batch is terminated by an end-of-batch signal. With the isql utility, this is the word "go" on a line by itself
    Local variables are declared, named, and typed with the declare keyword and are assigned an initial value with a select statement. They must be declared, assigned a value, and used within the same batch or procedure.
    Now which part of this do you not understand
    Last edited by pdreyer; 03-27-07 at 06:21.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts