Solved

varchar(8000) limits,how to overcome it in storedprocedure?

Posted on 2006-11-13
10
1,054 Views
Last Modified: 2012-05-05
Hello Expert,

I face problem where my varchar stores data which over 8000 char.
So i cant execute my storedprocedure. got error
May i know how to overcome this varchar(8000) limits?
The Following is my storedprocedure :

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go




Alter PROCEDURE [dbo].[MySP_ErrorLog]
AS
DECLARE @strXML varchar(8000)
DECLARE @idoc int
DECLARE @QueueID varchar(20)
DECLARE @XMLDATA varchar(8000)



DECLARE TB_LnItem_Cursor CURSOR FOR
Select QueueID, XMLData from tb_batchpocreation_Queue
Open TB_LnItem_Cursor

FETCH NEXT FROM TB_LnItem_Cursor INTO @QueueID, @XMLDATA
WHILE (@@fetch_status=0)
BEGIN
SET @strXML = @XMLDATA

EXEC sp_xml_preparedocument @idoc OUTPUT, @strXML
SELECT RegionCode
FROM OPENXML(@idoc, '/BatchPOCreation/Records/Record/RegionCode')
WITH (RegionCode varchar(250)
 
  )
EXEC sp_xml_removedocument @idoc

FETCH NEXT FROM TB_LnItem_Cursor INTO @QueueID, @XMLDATA

END
CLOSE TB_LnItem_Cursor
DEALLOCATE TB_LnItem_Cursor


My @XMLDATA stores over 8000 chars.


0
Comment
Question by:sonny_j81
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 11

Expert Comment

by:deroby
ID: 17929078
What version of MSSQL are you running ?

SQL2k5 supports both a varchar(max) (= virtually unlimited string) and a native xml datatype
0
 
LVL 1

Author Comment

by:sonny_j81
ID: 17929102
i am using SQL server 2000
0
 
LVL 1

Author Comment

by:sonny_j81
ID: 17929131
if sql server 2000 really cant do it, then i plan to directly read the xml data from crystal report.
But i dunno wat is the step to read the xmldata field which is stored in  tb_batchpocreation_Queue table?
Coz i need to retrieve Data inside this xmlData field.

The Data in xmldata field is like this:

<BatchPOCreation><Records><Record><ID>1</ID><RegionCode>SEL</RegionCode></Record></Records></BatchPOCreation>
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 11

Expert Comment

by:deroby
ID: 17929189
Honestly, I never really played with XML a lot as I'm lost why people would want to 'explode data' into a 'readable format' only to feed it to something that needs to convert it back to a record set.
Anyway, wouldn't it bee possible to use the prepare document statement as to create the output in one go and have that returned directly to Crystal Reports ?

(afaik Crystal Reports gladly acceppets recordsets, so why bother going via XML in the first place ? ... my 2 (heavily biased) cents )
0
 
LVL 11

Expert Comment

by:Otana
ID: 17929314
You could use multiple varchar(8000) variables, nad test the length each time you add something to them. If the first gets to 8000 characters, start filling the second, etc.
0
 
LVL 28

Accepted Solution

by:
imran_fast earned 500 total points
ID: 17929326
what is the datatype of XMLData in yourtable TB_LnItem_Cursor?
I think it is text or ntext
in that case you have to define 2 or three variables of varchar(8000)
and move first(8000) characters in variable1 and the rest in variable2

EXEC sp_xml_preparedocument @idoc OUTPUT, @strXML1 + isnull(@strXML2,'')
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17929339
try this

CREATE PROCEDURE [dbo].[MySP_ErrorLog]
 @strXML varchar(8000)  = null
AS
BEGIN
    DECLARE @idoc int
    DECLARE @QueueID varchar(20)
    DECLARE TB_LnItem_Cursor CURSOR FOR
    Select QueueID               --- Fetch only the QueID
    from tb_batchpocreation_Queue

    Open TB_LnItem_Cursor
   
    FETCH NEXT FROM TB_LnItem_Cursor INTO @QueueID
    WHILE (@@fetch_status=0)
    BEGIN
        SELECT @strXML = [XMLDATA]
        from tb_batchpocreation_Queue
       
        EXEC sp_xml_preparedocument @idoc OUTPUT, @strXML
        SELECT RegionCode
        FROM OPENXML(@idoc, '/BatchPOCreation/Records/Record/RegionCode')
        WITH (RegionCode varchar(250)
         
          )
        EXEC sp_xml_removedocument @idoc
       
        FETCH NEXT FROM TB_LnItem_Cursor INTO @QueueID
   
    END
    CLOSE TB_LnItem_Cursor
    DEALLOCATE TB_LnItem_Cursor

END

0
 
LVL 1

Author Comment

by:sonny_j81
ID: 17930524
Dear imran_fast,

Can u pls write in detail on how to store the first 8000 in first variable & the rest store in second variable?

Very Appreciate for your affort.
Thanks  
0
 
LVL 1

Author Comment

by:sonny_j81
ID: 17935202
Dear aneeshattingal,

i have paste your code and run it. The error occur which is "Msg 6603, Level 16, State 1, Procedure sp_xml_preparedocument, Line 19
XML parsing error: Element was not closed."
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17935291
can you compare the length of  both the XMLs using DATALENGTH()
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

839 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