Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Global Variable


Global Variable

Author
Message
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8356 Visits: 19492
If you have a couple of these suckers, and they are decently complex, the temp table is not a bad idea.


On this, I think we shall have to agree to disagree.

From BOL:

Global temporary tables are automatically dropped when the session that created the table ends and all other tasks have stopped referencing them. The association between a task and a table is maintained only for the life of a single Transact-SQL statement. This means that a global temporary table is dropped at the completion of the last Transact-SQL statement that was actively referencing the table when the creating session ended.


If this stuff is worth storing in a table and is going to be referenced by multiple scripts or procs, it should be held in a permanent table, not one which may disappear unexpectedly.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Erland Sommarskog
Erland Sommarskog
SSC Eights!
SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)

Group: General Forum Members
Points: 935 Visits: 866
Phil Parkin (7/31/2013)
[quote]If this stuff is worth storing in a table and is going to be referenced by multiple scripts or procs, it should be held in a permanent table, not one which may disappear unexpectedly.


My assumption was that we were talking about a single script, consisting of multiple batches. In which case a local temp table would do.

If we are talking about a multitude of scripts, global variables would not work, even if they existed(*). In that case, maybe the best option would be user-defined functions.

(*) Those who have worked with SQL Server for a long time, know that once there was something called "global variables", and indeed they had leading @@. But they were all pre-defined and readonly, that is @@spid, @procid and the like. Today they are referred to as functions, but you can still use them in context where normal built-in functions cannot be used.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8356 Visits: 19492
My assumption was that we were talking about a single script, consisting of multiple batches. In which case a local temp table would do


I see! I agree with your comments in that case :-)


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 5478

(*) Those who have worked with SQL Server for a long time, know that once there was something called "global variables", and indeed they had leading @@. But they were all pre-defined and readonly, that is @@spid, @procid and the like. Today they are referred to as functions, but you can still use them in context where normal built-in functions cannot be used.


Do you mean Sybase? I have worked with SQL server since their rebranded version of Sybase. Some people might called them as they used to in Sybase, but I cannot remember that these ones were ever refered to as "global variables" in MS SQL specs. Well, I could be very wrong, as it was really long-long ago, when I couldn't read in English :-D.

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Erland Sommarskog
Erland Sommarskog
SSC Eights!
SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)SSC Eights! (935 reputation)

Group: General Forum Members
Points: 935 Visits: 866
Eugene Elutin (7/31/2013)

Do you mean Sybase? I have worked with SQL server since their rebranded version of Sybase. Some people might called them as they used to in Sybase, but I cannot remember that these ones were ever refered to as "global variables" in MS SQL specs.


Here is a screenshot from Books Online for SQL 6.5 to prove it.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Attachments
BOL65.jpg (6 views, 86.00 KB)
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 5478
Erland Sommarskog (7/31/2013)
Eugene Elutin (7/31/2013)

Do you mean Sybase? I have worked with SQL server since their rebranded version of Sybase. Some people might called them as they used to in Sybase, but I cannot remember that these ones were ever refered to as "global variables" in MS SQL specs.


Here is a screenshot from Books Online for SQL 6.5 to prove it.


No need in proofs. I believe you! MS took Sybase docs and just searched-and-replaced "Sybase" with "SQL Server", why wouldn't they - it did saved them money and time...
Hehe

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search