Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Problem inserting xml string into temp table (inserting only a part of string not complete)

Problem inserting xml string into temp table (inserting only a part of string not complete)

Scheduled Pinned Locked Moved Database
helpdatabasexml
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sandeep kumar pundhir
    wrote on last edited by
    #1

    hi Can anyone resolve my problem> I create a temp table and inserts data into it through Xml String , spliting it by the character '|' . The data is inserted into the table fine but for last row it inserts only a part of it and does not inserts (" Remarks="">|) of the xml string. Can anyo please help or modify...the input xml string will be as given below. {TO KNOW THE PROBLEM PRACTICALLY COPY THIS CODE IN NEW QUERY EDITOR AND EXECUTE} --Declaring a temporary @TempTable declare @TempTable table ( AutoId int identity, items varchar(max) ) --Decaring a Variable Declare @ExcelDataInXml varchar(max) Set @ExcelDataInXml='||||||||

    E 1 Reply Last reply
    0
    • S sandeep kumar pundhir

      hi Can anyone resolve my problem> I create a temp table and inserts data into it through Xml String , spliting it by the character '|' . The data is inserted into the table fine but for last row it inserts only a part of it and does not inserts (" Remarks="">|) of the xml string. Can anyo please help or modify...the input xml string will be as given below. {TO KNOW THE PROBLEM PRACTICALLY COPY THIS CODE IN NEW QUERY EDITOR AND EXECUTE} --Declaring a temporary @TempTable declare @TempTable table ( AutoId int identity, items varchar(max) ) --Decaring a Variable Declare @ExcelDataInXml varchar(max) Set @ExcelDataInXml='||||||||

      E Offline
      E Offline
      Eric Dahlvang
      wrote on last edited by
      #2

      sandeep kumar pundhir wrote:

      insert into @TempTable select * from SPLIT(@ExcelDataInXml,'|')

      I assume that SPLIT() is a UDF? What does that function look like?

      --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

      S 1 Reply Last reply
      0
      • E Eric Dahlvang

        sandeep kumar pundhir wrote:

        insert into @TempTable select * from SPLIT(@ExcelDataInXml,'|')

        I assume that SPLIT() is a UDF? What does that function look like?

        --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

        S Offline
        S Offline
        sandeep kumar pundhir
        wrote on last edited by
        #3

        Yes SPLIT is a User Defined Function set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER FUNCTION [dbo].[Split](@String nvarchar(4000), @Delimiter char(1)) RETURNS @Results TABLE (Items nvarchar(4000)) AS BEGIN DECLARE @INDEX INT DECLARE @SLICE nvarchar(4000) -- HAVE TO SET TO 1 SO IT DOESNT EQUAL Z -- ERO FIRST TIME IN LOOP SELECT @INDEX = 1 -- following line added 10/06/04 as null -- values cause issues IF @String IS NULL RETURN WHILE @INDEX !=0 BEGIN -- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER SELECT @INDEX = CHARINDEX(@Delimiter,@STRING) -- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE IF @INDEX !=0 SELECT @SLICE = LEFT(@STRING,@INDEX - 1) ELSE SELECT @SLICE = @STRING -- PUT THE ITEM INTO THE RESULTS SET INSERT INTO @Results(Items) VALUES(@SLICE) -- CHOP THE ITEM REMOVED OFF THE MAIN STRING SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX) -- BREAK OUT IF WE ARE DONE IF LEN(@STRING) = 0 BREAK END RETURN END

        E 1 Reply Last reply
        0
        • S sandeep kumar pundhir

          Yes SPLIT is a User Defined Function set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER FUNCTION [dbo].[Split](@String nvarchar(4000), @Delimiter char(1)) RETURNS @Results TABLE (Items nvarchar(4000)) AS BEGIN DECLARE @INDEX INT DECLARE @SLICE nvarchar(4000) -- HAVE TO SET TO 1 SO IT DOESNT EQUAL Z -- ERO FIRST TIME IN LOOP SELECT @INDEX = 1 -- following line added 10/06/04 as null -- values cause issues IF @String IS NULL RETURN WHILE @INDEX !=0 BEGIN -- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER SELECT @INDEX = CHARINDEX(@Delimiter,@STRING) -- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE IF @INDEX !=0 SELECT @SLICE = LEFT(@STRING,@INDEX - 1) ELSE SELECT @SLICE = @STRING -- PUT THE ITEM INTO THE RESULTS SET INSERT INTO @Results(Items) VALUES(@SLICE) -- CHOP THE ITEM REMOVED OFF THE MAIN STRING SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX) -- BREAK OUT IF WE ARE DONE IF LEN(@STRING) = 0 BREAK END RETURN END

          E Offline
          E Offline
          Eric Dahlvang
          wrote on last edited by
          #4

          Your @ExcelDataInXml string is longer than 4000 characters, and your Split function only accepts 4000 characters.

          --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups