@@TRANCOUNT (variable or function)

  • The website below says that @@TRANCOUNT is a function.   But I read somewhere else that @@ is used to indicate a global variable.  How can a variable also be a function?

    http://www.dailyfreecode.com/code/trancount-trancount-function-437.aspx

  • The official documentation refers to them as functions. I suspect the fact they act a bit like variables, have similar syntax and the fact the correlation with ## and # tables has lead to people calling them global variables, even though they really aren't.

  • andycadley - Monday, October 15, 2018 6:21 PM

    The official documentation refers to them as functions. I suspect the fact they act a bit like variables, have similar syntax and the fact the correlation with ## and # tables has lead to people calling them global variables, even though they really aren't.

    Thank you for clarifying.  Then just to be sure, what does the @@ indicate?

  • Nothing. It has no special meaning by itself.

    This works fine, but has no meaning difference to any other variable
    DECLARE @@i INT
    SET @@i = 1;
    SELECT @@i

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply