Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Removing variables and testing for their existence

Author  Topic 

Rangi
Starting Member

18 Posts

Posted - 2002-12-05 : 09:21:34
In SQL Server 2000, Is it possible to manually remove variables? eg.

DECLARE @i int
SET @i = 10
UN_DECLARE @i     -- I know this doesn't exist but is there anything like this?

Also, is there a way to test if a variable exists, as in:

IF (VARIABLE_EXISTS @myVar) PRINT 'Variable exists'

Again, I know there is no function called VARIABLE_EXISTS, but I am hoping you will be able to see what I am looking for.

Any help would be much appreciated.

Rangi

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-12-05 : 09:30:45
What are you trying to do with such a feature? You're right that it doesn't exist, but I don't see what need you'd have for it anyway.

Go to Top of Page

Rangi
Starting Member

18 Posts

Posted - 2002-12-05 : 09:49:33
I don't actually need them, was just curious really, as I am quite new to SQL but have experience in other languages.

Thanks,

Rangi




Edited by - Rangi on 12/05/2002 09:49:58
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-12-05 : 10:02:07
What you are looking for is to define the scope of a variable.

If the variable doesn't exist then the SP won't compile so there's no point in checking at run time.

You can call other stored procedures which use the variable to emulate scope but there's probably not much point.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -