Solved

Declaring Sybase local variables

Posted on 2000-03-31
11
2,698 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
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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A safe way to clean winsxs folder from your windows server 2008 R2 editions
A Short Story about the Best File Recovery Software – Acronis True Image 2017
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now