Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databaseshello 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
Post Follow-up to this messageSee LEN() and "String Functions" in Books Online. Simon
Post Follow-up to this messageSelect len(field) or Select DataLength(field) Madhivanan
Post Follow-up to this messageBe 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
Post Follow-up to this messagethanx for all for valuable information! best wishes Adam
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread