Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6367193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:31:04+00:00 2026-05-25T00:31:04+00:00

I’m trying to write a stored procedure in which I insert a few things

  • 0

I’m trying to write a stored procedure in which I insert a few things from an XML string.
This is to avoid making lots of stored procedure calls from inside a loop.

This is what I got so far, but its giving me errors:

Msg 207, Level 16, State 1, Procedure newsMapper_prc, Line 22
Invalid column name ‘headline’.
Msg 207, Level 16, State 1, Procedure newsMapper_prc, Line 22
Invalid column name ‘story’.
Msg 207, Level 16, State 1, Procedure newsMapper_prc, Line 25
Invalid column name ‘entity’.
Msg 207, Level 16, State 1, Procedure newsMapper_prc, Line 27
Invalid column name ‘entity’.

Can’t really figure this out, some help would be greatly appreciated

<newsfile>
    <headline>THIS IS A NEWS HEADLINE</headline>
    <story>THIS IS A NEWS STORY</story>
    <entity>  1234</entity>
    <entity>1111</entity>
    <entity>2222</entity>
</newsfile>

Stored procedure code:

CREATE PROCEDURE newsMapper_prc
-- Add the parameters for the stored procedure here
  (@xmlString xml)
AS
 declare @criteriaTable table (criterianame varchar(100), parm varchar(MAX))

insert into @criteriaTable 
Select 
    criteriaValues.parm.value('../@type','varchar(MAX)'),
    criteriaValues.parm.value('.','varchar(MAX)')
from @xmlString.nodes('/newsfile/headline') as headline(parm),
 @xmlString.nodes('/newsfile/headline/story') as story(parm),
 @xmlString.nodes('/newsfile/headline/story/entity') as entity(parm)

insert into News (newsHeadline, newsStory, newsDate) values ((select headline from            @criteriaTable),(select story from @criteriaTable), GETDATE())
declare @newsID int
SET @newsID = scope_identity()
while exists (select entity from @criteriaTable)
BEGIN
insert into NewsEntities(newsID,entityID) values (@newsID,( Select entity from @criteriaTable))
END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:31:05+00:00Added an answer on May 25, 2026 at 12:31 am

    Given your XML

    DECLARE @input XML
    SET @input = '<newsfile>
        <headline>THIS IS A NEWS HEADLINE</headline>
        <story>THIS IS A NEWS STORY</story>
        <entity>  1234</entity>
        <entity>1111</entity>
        <entity>2222</entity>
    </newsfile>'
    

    using this T-SQL statement, you can “rip apart” your XML into rows and columns:

    SELECT
        NF.Ent.value('(.)[1]', 'int') AS 'Entity',
        @input.value('(/newsfile/headline)[1]', 'varchar(100)') AS 'Headline',
        @input.value('(/newsfile/story)[1]', 'varchar(100)') AS 'Story'
    FROM
        @input.nodes('/newsfile/entity') AS NF(Ent)
    

    this gives you:

    Entity  Headline                  Story
    1234    THIS IS A NEWS HEADLINE   THIS IS A NEWS STORY
    1111    THIS IS A NEWS HEADLINE   THIS IS A NEWS STORY
    2222    THIS IS A NEWS HEADLINE   THIS IS A NEWS STORY
    

    Now what do you want to do with this information?? I can’t quite understand what your stored proc is trying to do…..

    If I understand correctly – you want to insert the headline and the story into the News table and get the IDENTITY ID back:

    INSERT INTO dbo.News(newsHeadline, newsStory, newsDate) 
        SELECT
            @input.value('(/newsfile/headline)[1]', 'varchar(100)') AS 'Headline',
            @input.value('(/newsfile/story)[1]', 'varchar(100)') AS 'Story',
            GETDATE()
    
    DECLARE @NewsID INT
    SET @NewsID = SCOPE_IDENTITY()
    

    and then you want to add an entry into the NewsEntities table for each value of <entity> in your XML – correct?

    INSERT INTO dbo.NewsEntities(NewsID, EntityID)
        SELECT
            @NewsID,
            NF.Ent.value('(.)[1]', 'int')
    FROM
        @input.nodes('/newsfile/entity') AS NF(Ent)
    

    If you put this all together – does that solve your problem?=

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a bunch of posts stored in text files formatted in yaml/textile (from
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.