High Plains Grifter (9/24/2012)
Thanks Chris and GSquared for replies and speed!I see how those work; my concern is that using things like REPLACE(),LEN(),LEFT() on a text field of more than 8000 characters will truncate the length down to 8000 characters, meaning that I could lose data off the end of my fieldvalue; the example below will return 8000:
DECLARE @String VARCHAR(MAX) = REPLICATE('a',10000)
SELECT LEN(@String)
I am using SQL Server 2008 R2, so the VARCHAR(MAX) should be able to hold something like 2^31 characters
Edit:
Wow - you post faster than I do! I hear you about the need for sample data - taken on board. Unfortunately, we are using a database built by an external software company and have no real control over the format.
DECLARE @String VARCHAR(MAX) = REPLICATE(CAST('a' AS VARCHAR(MAX)),10000)
SELECT LEN(@String)
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden