January 12, 2005 at 4:11 pm
Hello.
Looking into the Trigger BOL help I realized into one example that uses @@VarName
CREATE TRIGGER employee_insupd
ON employee
FOR INSERT, UPDATE
AS
/* Get the range of level for this job type from the jobs table. */
DECLARE @@MIN_LVL tinyint,
@@MAX_LVL tinyint,
@@EMP_LVL tinyint,
@@JOB_ID smallint
SELECT @@MIN_LVl = min_lvl,
@@MAX_LV = max_lvl,
@@ EMP_LVL = i.job_lvl,
@@JOB_ID = i.job_id
FROM employee e, jobs j, inserted i
WHERE e.emp_id = i.emp_id AND i.job_id = j.job_id
IF (@@JOB_ID = 1) and (@@EMP_lVl <> 10)
BEGIN
RAISERROR ('Job id 1 expects the default level of 10.', 16, 1)
ROLLBACK TRANSACTION
END
ELSE
IF NOT @@ EMP_LVL BETWEEN @@MIN_LVL AND @@MAX_LVL)
BEGIN
RAISERROR ('The level for job_id:%d should be between %d and %d.',
16, 1, @@JOB_ID, @@MIN_LVL, @@MAX_LVL)
ROLLBACK TRANSACTION
ENDWhat are @@ for? What's the difference between using a single @?
I've benn looking in BOL, but can't find anything helpful
Thanks
January 12, 2005 at 4:19 pm
@@ is a global value
@ is a local value exist only on that connection.
mom
January 12, 2005 at 4:23 pm
Thanks, I suspected that.
And in the example, what are the benefits of using global variables instead of using local ones?
January 12, 2005 at 4:44 pm
Not specifically for this example, but the only benefit I've ever known for a Global Variable is if you have multi processes which need to know what that variable is at that particular given moment, regardless of what processes you have running. It stays up and available to other connections. Since I want full control of what the variable is at all times, then I only use local variables. I suppose if I didn't want to pass a variable value to a nested sproc, then I could use a global, but I'd rather pass the value in the exec statement.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply