How to check if a variable is already declared (T-SQL)?

前端 未结 2 837
感动是毒
感动是毒 2021-01-07 22:11

When I write

DECLARE @x INT

Is there a way to check whether the variable @x has already been declared or not?

2条回答
  •  [愿得一人]
    2021-01-07 22:36

    IF you try to access a variable that has not yet been defined, the T-SQL Script will give you an error telling you the variable isn't defined.

    Msg 137, Level 15, State 2, Line 5 Must declare the scalar variable "@x".

提交回复
热议问题