SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Adding Global and Scope Variables


Adding Global and Scope Variables

Author
Message
wshmstr
wshmstr
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 80
There must be an life saving global variables to use per connection like:

DECLARE @@MYVAR1 BIGINT
DECLARE @@MYVAR2 VARCHAR(30)

SET @@MYVAR1 = 123456
SET @@MYVAR2 = 'Username'

So we can use it to pass or use them anywhere on the sql server.
For eg: When a user opens my application, I'll pass @@MYVAR1 and @@MYVAR2.
Then I'll assign fields default value to @@MYVAR1 and @@MYVAR2 so I never ever need to pass extra params from application to stored procedures or queries to save them in tables. Also this is very useful if you want to do table or record security works.
Charles Kincaid
Charles Kincaid
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1663 Visits: 2384
I can see many uses for it. I can also see the two at sign notation carring on the "tradition" of temp tables.

Conversly would name spaces be better for this?
@session.myusername = 'Buford H. Pusser'
@server.panicphone = '202-456-1414'

Who gets to set server variables? Who gets to change them? When they get changed when do I see the effect of the change?

ATBCharles Kincaid
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