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 6609935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:46:37+00:00 2026-05-25T19:46:37+00:00

I do something like this: CREATE PROCEDURE [dbo].[InsertStudents] ( @students nvarchar(max) ) AS DECLARE

  • 0

I do something like this:

CREATE PROCEDURE [dbo].[InsertStudents]
(
    @students nvarchar(max)
)
AS
DECLARE @studentstable TABLE
(
    RowIndex int,
    FirstName nvarchar(50),
    LastName nvarchar(50),
    Number nvarchar(20),
    IdSchool int
)
DECLARE @xmldata xml
SET @xmldata = @students
INSERT INTO @studentstable
SELECT S.Stud.query('./RowIndex').value('.','int') RowIndex, 
       S.Stud.query('./FirstName').value('.','nvarchar(50)') FirstName,
       S.Stud.query('./LastName').value('.','nvarchar(50)') LastName,
       S.Stud.query('./Number').value('.','nvarchar(50)') Number,
       S.Stud.query('./IdSchool').value('.','int') IdSchool,
FROM @xmldata.nodes('/Students/Student') AS S(Stud)   

 DECLARE @totalrows int
 DECLARE @currentrow int
 DECLARE @totalinserts int

 DECLARE @currentfirstname nvarchar(50)
 DECLARE @currentlastname nvarchar(50)
 DECLARE @currentnumber nvarchar(20)
 DECLARE @currentidschool int

 DECLARE @insertresult int

 SET @totalinserts = 0
 SET @totalrows=(SELECT COUNT(*) FROM @studentstable)
 SET @currentrow=0

 WHILE(@currentrow<@totalrows) BEGIN
    SELECT @currentfirstname = FirstName, @currentlastname = LastName, @currentnumber = Number, @currentidschool = IdSchool
    FROM @studentstable
    WHERE RowIndex=@currentrow
    EXEC @insertresult = InsertStudent @currentfirstname, @currentlastname, @currentnumber, @currentidschool
    IF @insertresult=0 BEGIN
        SET @totalinserts=@totalinserts+1
    END 
    SET @currentrow = @currentrow + 1
 END
 SELECT @totalinserts

InsertStudent returns 0 if insert worked or 1 if there is already a student with that number.

Isn’t there any way to do it without messing with that variable table?

  • 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-25T19:46:37+00:00Added an answer on May 25, 2026 at 7:46 pm

    Something like this using merge.

    merge Student
    using (select S.Stud.query('./RowIndex').value('.','int') RowIndex, 
                  S.Stud.query('./FirstName').value('.','nvarchar(50)') FirstName,
                  S.Stud.query('./LastName').value('.','nvarchar(50)') LastName,
                  S.Stud.query('./Number').value('.','nvarchar(50)') Number,
                  S.Stud.query('./IdSchool').value('.','int') IdSchool
           from @xmldata.nodes('/Students/Student') as S(Stud)) as SXML
    on Student.Number = SXML.Number
    when not matched then
      insert (FirstName, LastName, Number, IdSchool)
        values (SXML.FirstName, SXML.LastName, SXML.Number, SXML.IdSchool);
    
    select @@rowcount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do something like this: create table app_users ( app_user_id smallint(6) not
I'm creating a table that looks something like this. CREATE TABLE packages ( productCode
is it possible to create something like this i ASP.NET MVC beta 1 i
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create a wpf treeviewlist to look something like this: AAAA BBBB
when i create an aspx page, the header includes something like this:- <%@ Page
Something like this might had worked <%= Html.RouteLink(, new { controller = Article, action
Using something like this: try: # Something... except Exception as excep: logger = logging.getLogger(component)
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of

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.