Solved

SQL Server Select LEN on XML

Posted on 2013-07-01
4
681 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now