Showing posts with label chars. Show all posts
Showing posts with label chars. Show all posts

Monday, March 19, 2012

how many chars in varchar record

hello

How could I check how many chars are in record, defined as varchar(8000).
It's obvious that in such defined record could be 1 char to 8000 char. But
what query to SQL database should I post to give information about realy
lenght of this records ?

thanks from advance

AdamSee LEN() and "String Functions" in Books Online.

Simon|||Select len(field)
or
Select DataLength(field)

Madhivanan|||Be careful - the two functions are not the same. LEN() returns the
number of characters after removing trailing blanks, but DATALENGTH()
returns the number of bytes stored. So you can get different results if
trailing blanks are present, if you have varchar vs char, or if you use
Unicode columns - see the code below, and Books Online for more
details.

Simon

create table #t (v varchar(10), nv nvarchar(10))

insert into #t select 'X', 'X'
insert into #t select 'X ', 'X ' -- two trailing blanks

select len(v), datalength(v), len(nv), datalength(nv)
from #t

create table #t1 (c char(10), nc nchar(10))

insert into #t1 select 'X', 'X'
insert into #t1 select 'X ', 'X ' -- two trailing blanks

select len(c), datalength(c), len(nc), datalength(nc)
from #t1|||Thanks Simon

Madhivanan|||thanx for all for valuable information!

best wishes
Adam

How many chars in text field?

How many characters can you fit inside a text field with a length of 16.
How do you work this out?
Thanks
JF16 is only the size of the pointer which points to the actual data location.
Max size for the blob datatypes is approx 2GB.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Jof" <john.fletcher@.servicedelivery.org.uk> wrote in message
news:8809e3fb.0403190333.1db6e042@.posting.google.com...
> How many characters can you fit inside a text field with a length of 16.
> How do you work this out?
> Thanks
> JF|||To add to Tibor's response, the reported column size for text/ntext/image
data is the maximum number of bytes which are actually stored in the data
page. The 16-byte value is the default (pointer to separate text/image
page) but is configurable in SQL 2000 with the 'text in row' table option.
This allows you to control how much data cam be stored with the row itself
but the max data size is still 2GB.
Hope this helps.
Dan Guzman
SQL Server MVP
"Jof" <john.fletcher@.servicedelivery.org.uk> wrote in message
news:8809e3fb.0403190333.1db6e042@.posting.google.com...
> How many characters can you fit inside a text field with a length of 16.
> How do you work this out?
> Thanks
> JF