Home > Archive > Microsoft SQL Server forum > August 2005 > how many char's in varchar record









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how many char's in varchar record
adam

2005-08-22, 7:24 am

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

Adam

Simon Hayes

2005-08-22, 7:24 am

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

Simon

Madhivanan

2005-08-22, 9:23 am


Select len(field)
or
Select DataLength(field)

Madhivanan

Simon Hayes

2005-08-22, 9:23 am

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

Madhivanan

2005-08-22, 9:23 am

Thanks Simon

Madhivanan

adam

2005-08-22, 8:23 pm

thanx for all for valuable information!

best wishes
Adam

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com