When I run this T-SQL on a SQL Server 2016 database with compatibility level 130 I get an error:
DECLARE @myVariable int = 4;
EXEC sys.sp_addextendedproperty
@name = N'MyExtendedProperty',
@value = FORMAT( @myVariable, 'd', 'en-US' ),
@level0type = N'SCHEMA', @level0name=N'dbo',
@level1type = N'TABLE' , @level1name=N'MyTable';
The error message is below, and SSMS highlights the use of @myVariable
within the FORMAT
function call:
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '@myVariable'
But if I use an intermediate variable the SQL runs successfully:
DECLARE @myVariable int = 4;
DECLARE @myVariableText nvarchar(10) = FORMAT( @myVariable, 'd', 'en-US' )
EXEC sys.sp_addextendedproperty
@name = N'MyExtendedProperty',
@value = @myVariableText,
@level0type = N'SCHEMA', @level0name=N'dbo',
@level1type = N'TABLE' , @level1name=N'MyTable';
I did wonder if FORMAT
or sp_addextendedproperty
is a magical function like RAISERROR
which requires the first argument to be a string literal (no expressions allowed) but the documentation for sp_addextendedproperty
does not mention any restrictions on the @value
parameter:
[ @value= ] { 'value'}
Is the value to be associated with the property. value is
sql_variant
, with a default of NULL. The size of value cannot be more than 7,500 bytes.