Data type variable size in sql

How to find out the size of data in sql. For example, if I declared a variable or column as

declare @test varchar(255)


Then I need the size of the @test datatype variable to display as 255.

EDIT: Now I know how to get it for a column, is there a way for a variable?


source to share

1 answer

You can use sql_variant_property .

declare @test varchar(255)
set @test = '' --Must assign a value
select sql_variant_property(@test, 'MaxLength')




All Articles