Sql-server – way to make a TSQL variable constant

sql-servertsql

Is there a way to make a TSQL variable constant?

Best Solution

No, but you can create a function and hardcode it in there and use that.

Here is an example:

CREATE FUNCTION fnConstant()
RETURNS INT
AS
BEGIN
    RETURN 2
END
GO

SELECT dbo.fnConstant()