sonny_j81
asked on
varchar(8000) limits,how to overcome it in storedprocedure?
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/Reg ionCode')
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.
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/
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.
ASKER
i am using SQL server 2000
ASKER
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><I D>1</ID><R egionCode> SEL</Regio nCode></Re cord></Rec ords></Bat chPOCreati on>
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>
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 )
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 )
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/Reg ionCode')
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
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/
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
ASKER
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
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
ASKER
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."
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."
can you compare the length of both the XMLs using DATALENGTH()
SQL2k5 supports both a varchar(max) (= virtually unlimited string) and a native xml datatype