What are the challenges you face when working across database platforms? Take the survey

Variables are never used

Hi Redgate Team,

The code analysis reports that the variables are never used but obviously it is not the case.

    @inaccessible   nvarchar(12),
    @invalidlogin   nvarchar(12),
    @dbinaccessible nvarchar(12);
SELECT @inaccessible = LTRIM(STR(CONVERT(int, 0x03e0), 11));
SELECT @invalidlogin = LTRIM(STR(CONVERT(int, 0x40000000), 11));
SELECT @dbinaccessible = N'0x80000000'; /* SQLDMODbUserProf_InaccessibleDb; the negative number doesn't work in convert() */

I am using the latest version of SQL Prompt.

Thanks for looking into this.



  • Options
    Hi Torsten,

    The Prompt team has confirmed that in the example you reported, the variable is declared and assigned, but it is never "consumed"/"read". They appreciate it would be a good idea to split it into 2 rules:
    1- Variable declared but not used.
    2- Variable assigned but not used.

    However, at the moment they are not planning to make this change in the near future due to other concerns. We still have it logged in our system as SP-6765  though and we'll reassess it again in the future.
    Have you visited our Help Centre?
Sign In or Register to comment.