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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-06-16 : 08:09:28
|
| Deepa writes "I have package spec defined in ORACLE as follows in which I declare a global temporary variable.CREATE OR REPLACE PACKAGE TESTPKG AS CTR NUMBER(3) := 0;END TESTPKG;**************************************************************I have a table defined as follows :CREATE TABLE TESTC(ctr number(3));**************************************************************I have a proc in which I call this variable for the purpose of Insertion into a table TestC.CREATE OR REPLACE PROCEDURE TESTPROC ASBEGINTESTPKG.CTR := TESTPKG.CTR + 1;INSERT INTO TESTC VALUES(TESTPKG.CTR);COMMIT;END TESTPROC;**************************************************************Now when I execute Procedure TESTPROC for the (a) First Time :select * from TestC gives me 1(b) Second Time :select * from TestC gives me 2(c) Third Timeselect * from TestC gives me 3I disconnect the session and re-connectNow I again execute the proc and do a select * from testCand this will now yield me 1My question is :What is the Equivalent or work-around for handling this situation in MS-SQL server." |
|
|
Crito
Starting Member
40 Posts |
Posted - 2005-06-16 : 10:35:18
|
| A global variable name in Transact-SQL must begin with @@ and a global temp table name must begin with ##, as opposed to a local var that begins with a single @ and a local temp table that begins with single #. Both are bound to the specific connection/session and those resources are automatically freed when its disconnected/closed, just like in Oracle. |
 |
|
|
|
|
|