Is it possible to find out runtime using t-sql if a type (e.g. nvarchar or int) is fixed-length or not by querying some system-table?
The reason I need to do this is that I need to generate sql-code runtime and need to generate some declarations (DECLARE @foo SOMETYPE(LENGTH)
or DECLARE @foo SOMETYPE
) depending on the type of some columns (that are unknown at design-time).
My current bet is that I can check if sys.all_columns.max_length = sys.types.max_length
and if so assume that it is fixed-length (since max_length
seems to have a special code (-1), at least for nvarchar).