Solved

Declaring Sybase local variables

Posted on 2000-03-31
11
2,945 Views
Last Modified: 2008-03-17
Hi, I am new to Sybase. I tried to declare local variables in an isql session on Hp-ux.
> declare @count int
> go
I get a syntax on count. This is an example straight from the book. I think the problem could be with the emulator's interpretation of metacharacters?

Could somebody help me overcome the problem?
I tried three different emulators Outsideview, QVT and Secure CRT,

-Thanks
Krishna
0
Comment
Question by:kthota
[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
11 Comments
 

Expert Comment

by:Alex_nl
ID: 2675758
I'm not sure but could it be that 'count' is a reserved word so you cannot use it? What if you tried another variable name like icount or something?

Alex
0
 

Expert Comment

by:NickMorgan
ID: 2679184
What is the exact error message?
Count is a reserved word but I don't think that should be a problem.

Try
select @@servername
go

which should return your sybase server name.

Cheers,Nick
0
 
LVL 3

Expert Comment

by:ahoor
ID: 2679278
Khota,
should not be a problem... so you get the error from the declare or
afterwards when you try to use it...

this is a copy created on Sun

1> declare @count int
2> go
1> select @count = 1
2> go
Msg 137, Level 15, State 1:
Server 'SYBASE25', Line 1:
Must declare variable '@count'.
1>

The declare goes well but you can't use it because it's not in a batch.
In that case, you use begin/end.

1> begin
2> declare @count int
3> select @count = 1
4> select @count
5> end
6> go
(1 row affected)

 -----------
           1
(1 row affected)
1>
0
Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

 

Author Comment

by:kthota
ID: 2680658
Hi Guys,
       None of the above suggestions seem to work. I am pasting what I did for you perusal. I think the issue is not with the syntax one way or the other. This should be an emulation issue. But I don't know a whole lot about emulators to change the configuration. Actually I tried using atleast three different emulators, namely Outside view, Qvtnet, Secure-crt and even a plain run telnet from windows 98.This last one was emulating VT-100/ANSI.
1> declare @vchar varchar(20)
2> go
Msg 102, Level 15, State 1:
Line 1:
Incorrect syntax near '20'.
1> declare @vchar varchar(20)
2> go
Msg 102, Level 15, State 1:
Line 1:
Incorrect syntax near '20'.
1>

Hope somebody can shed light on the quirks of emulators
-Krishna              
0
 
LVL 2

Expert Comment

by:ajith_29
ID: 2690330
hi kthota,
Do not use go after the declare statement when u have finished giving the commands to be done by the server then give the go.The go is used to show that your through with your commands and its time for the sql to be executed in simple terms.
If you have a go after the declare then the variable is not found by the sql because its gone in another session.
The simple answers is after you finished typing the commands then use go statement.
0
 

Author Comment

by:kthota
ID: 2694040
Hi Ajith, I don't think there is anything wrong with executing a go after declaring local variable.After the declaration I could say select @vchar1 to display the null contents of the variable and then say go. That would still not help.
1>
2> declare @vchar1 varchar(20)
3> select @vchar1
4> go
Msg 102, Level 15, State 1:
Line 2:
Incorrect syntax near '20'.
1>                        
Do you see anything wrong in what I typed above. If so how would I ever get to use the variables without the go. The above would be a simple test batch

Again I think this a problem with the emulator that I am using. Somehow things are not fine between isql and my emulator. I do not have any problems using the emulator for performing other unix tasks
-Krishna
0
 
LVL 1

Expert Comment

by:andres
ID: 2724072
try bellow:

declare @vchar1 varchar;
select @vchar1;
go
0
 

Author Comment

by:kthota
ID: 2724149
Hi,
   I could get what ever I typed from a script. But the same does  not work interactively. Even with the script I had to do a CTRL V before typing @. I wonder what could be done to make this work interactively
0
 

Expert Comment

by:jesumib
ID: 2797294
Hi kthota,

Maybe something in your isql in unix is wrong.

I think you can use other software to get interactivity to Sybase, not to change the emulators.

Example, I like to use RapidSQL from Embarcadero http://www.embarcadero.com/ 

There is a evaluation to download, you
only need open client in your PC to define your server in sql.ini, i.e.

[HP9000]
query=NLWNSCK,132.1.1.3,4050


0
 
LVL 5

Accepted Solution

by:
amitpagarwal earned 5 total points
ID: 2919636
u got that error as count is a reserved word in sybase.

try some other variable name
0
 
LVL 3

Expert Comment

by:ahoor
ID: 2920386
Amit etc please read previous responses before posting an answer *sigh*
0

Featured Post

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

628 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