It not really a problem but i am curious to know why.
I am using sql server and using FORMAT
in a number returns a varchar with 4000 lenght. Why?
select format(1,'00')
This query returns "01"
It not really a problem but i am curious to know why.
I am using sql server and using FORMAT
in a number returns a varchar with 4000 lenght. Why?
select format(1,'00')
This query returns "01"
Consider a query like
drop table if exists #t
create table #t(val int, fmt varchar(20))
insert into #t(val,fmt) values (1,'00')
insert into #t(val,fmt) values (1,'0000000')
insert into #t(val,fmt) values (1,'0000000000000000000')
select format(val,fmt) formatted from #t
What data type should formatted
be? It can't change per row, so a single type must be chosen to hold all the values. And nvarchar(4000)
is a reasonable choice, as it can hold any string with up to 4000 characters.