What’s the difference between accessing a variable with @ or without?
What’s the difference between accessing a variable with @ or without?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
@makes it a user defined session variable. Otherwise it would be locally scoped variable (in a stored procedure), you would have toDEFINEyour local before you canSETit. You could also set a global system variable (withSET GLOBALorSET @@global) if you wanted to. As well as a session system variable withSET SESSION varorSET @@session varorSET @@var.More details about
SETfrom the documentation: If no modifier is present,SETchanges the session variable (that’s why youDEFINEyour locals in the stored procedure first). If you set several system variables, the most recentGLOBALorSESSIONmodifier in the statement is used for following variables that have no modifier specified.More (and some good examples) here: