Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

declaring global variables Expand / Collapse
Author
Message
Posted Saturday, October 9, 2010 1:59 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, January 6, 2014 4:32 AM
Points: 127, Visits: 350
Hi,

In Oracle, we can set the public variable/constant/types/curosors in the Package specification, Could you please tell me that how to achieve the same functionality in the SQL server.

Thanks in Advance
Post #1001681
Posted Sunday, October 10, 2010 6:47 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,068, Visits: 4,639
mail4sha (10/9/2010)
In Oracle, we can set the public variable/constant/types/curosors in the Package specification, Could you please tell me that how to achieve the same functionality in the SQL server.

There is not such a thing as a package in SQL Server but you use DECLARE statement to declare variables, etc. Check here... http://msdn.microsoft.com/en-us/library/aa258839(SQL.80).aspx

Hope this helps.



_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #1001865
Posted Monday, March 7, 2011 5:34 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, July 8, 2014 2:57 AM
Points: 369, Visits: 1,208
No packages in SQL Server, unfortunately. Packages are one of Oracle advantages over SQL Server (do not start a war, please :) ).
But, you have several other options to make data shareable between procedures (beside obvoius: parameters):

#temporary tables
##global temporary tables
context_info - 128 bytes of connection-scoped data. varbinary(128), initially NULL.
declare @vb varbinary(128)
set @vb = context_info() -- read value
set context_info @vb -- set value

You can use e.g. one byte of the binary string for one variable, next four bytes for other variable etc.
Also, @table variables can be input parameters for procedure from sql2008 and up.


_____________________________________________________
Microsoft Certified Master: SQL Server 2008
XDetails Addin - for SQL Developers
blog.sqlxdetails.com - Transaction log myths
Post #1074549
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse