Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL Server Select LEN on XML

Posted on 2013-07-01
4
697 Views
Last Modified: 2013-07-01
What is the best way for me to get a true "Length" on an XML field that was inserted using a HttpWebResponse chunked response and a read buffer like this in VB
streamRead.Read(readBuff, 0, 5120)


This is my select
SELECT LEN(CAST(XmlDoc AS VARCHAR(MAX))) xmlDoc FROM      [dbo].[VOIPXMLTransactionLog]

But it seems to be ignoring spaces?
0
Comment
Question by:lrbrister
  • 2
4 Comments
 
LVL 13

Expert Comment

by:jonnidip
ID: 39291097
Are you sure that spaces are in the variable?
Where are you openinig your file? Maybe in a "visual" editor (just like Internet Explorer)? If so, you may see spaces where there are only tabs, or maybe nothing...
Some viewers/editors apply formatting to XML files.
Please ensure you are not in this case...


Regards.
0
 

Author Comment

by:lrbrister
ID: 39291104
I'm not looking at it in a viewer.

I'm getting a response stream and sending it straight to SQL Server.
0
 
LVL 11

Accepted Solution

by:
lenordiste earned 500 total points
ID: 39291106
that SQL statement looks fine. LEN does take into account spaces so this should give you the result you are looking for. Why do you think it is not working as intended? The only thing I can think of is that LEN does not count trailing spaces!

as a side note, you can also use the function datalength which returns the size in bytes, including trailing blanks:
http://msdn.microsoft.com/en-us/library/ms173486(SQL.90).aspx
0
 

Author Closing Comment

by:lrbrister
ID: 39291173
That was it...the DataLength
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question