Is there a way to make a TSQL variable constant?

前端 未结 12 1050
别那么骄傲
别那么骄傲 2021-02-01 11:31

Is there a way to make a TSQL variable constant?

12条回答
  •  一整个雨季
    2021-02-01 12:16

    Since there is no build in support for constants, my solution is very simple.

    Since this is not supported:

    Declare Constant @supplement int = 240
    SELECT price + @supplement
    FROM   what_does_it_cost
    

    I would simply convert it to

    SELECT price + 240/*CONSTANT:supplement*/
    FROM   what_does_it_cost
    

    Obviously, this relies on the whole thing (the value without trailing space and the comment) to be unique. Changing it is possible with a global search and replace.

提交回复
热议问题