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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:42:13+00:00 2026-06-15T23:42:13+00:00

ALTER PROCEDURE [dbo].[sp_Insert_Monthly_Salary_Req] @xmlString ntext ,@Message nvarchar(500) output AS BEGIN SET NOCOUNT ON; declare

  • 0
ALTER PROCEDURE [dbo].[sp_Insert_Monthly_Salary_Req]
     @xmlString  ntext
    ,@Message nvarchar(500) output
AS
BEGIN

    SET NOCOUNT ON;
    declare  @Emp_SL int,@Basic  decimal(6,2), @Grad_pay  decimal(6,2), @DA  decimal(6,2), @HRA  decimal(6,2), @MA  decimal(6,2), @Ptax  decimal(6,2), @Itax  decimal(6,2), @pf  decimal(6,2), @LIC  decimal(6,2), @Month_Of  datetime
    Declare @intDoc1 as int
    BEGIN TRANSACTION 
    print @xmlString
    exec sp_xml_preparedocument @intDoc1 OUTPUT, @xmlString
    declare Generate_Rq CURSOR FOR
    SELECT Emp_SL,Basic, Grad_pay, DA, HRA, MA, Ptax, Itax, pf, LIC,  Month_Of
    FROM OPENXML (@intDoc1,'/Salaray/TransactionSalary',1)
    WITH ( Emp_SL int,Basic  decimal(6,2), Grad_pay  decimal(6,2), DA  decimal(6,2), HRA  decimal(6,2), MA  decimal(6,2), Ptax  decimal(6,2), Itax  decimal(6,2), pf  decimal(6,2), LIC  decimal(6,2), Month_Of  datetime)

    OPEN Generate_Rq
    FETCH next FROM Generate_Rq
    INTO @Emp_SL,@Basic, @Grad_pay, @DA, @HRA, @MA, @Ptax, @Itax, @pf, @LIC,  @Month_Of
    print 'Line2'
    WHILE @@Fetch_Status<>-1
        BEGIN
            Print 'Line  ' +@Basic+ '    '+ @Grad_pay+ '    '+ @DA+ '    '+ @HRA+ '    '+ @MA+ '    '+ @Ptax+ '    '+ @Itax+ '    '+ @pf+ '    '+ @Month_Of+ '    '+ @LIC+ '    '+ @Emp_SL

            INSERT INTO [Monthly_Salary_Statement]([Basic], [Grad_pay], [DA], [HRA], [MA], [Ptax], [Itax], [pf], [Month_Of], [LIC], [Emp_SL])
            VALUES (@Emp_SL,@Basic, @Grad_pay, @DA, @HRA, @MA, @Ptax, @Itax, @pf, @LIC,  @Month_Of)
            if(@@ERROR<>0)
                BEGIN
                    rollback transaction
                    Set @Message='sp_Insert_PromtList: ' + @@Error 
                    close Generate_Rq
                    deallocate Generate_Rq
                    Return
                END
            FETCH next FROM Generate_Rq
            INTO @Emp_SL,@Basic, @Grad_pay, @DA, @HRA, @MA, @Ptax, @Itax, @pf, @LIC,  @Month_Of
        END
    CLOSE Generate_Rq
    DEALLOCATE Generate_Rq
    COMMIT TRANSACTION
    set  @Message='True'
END

The xml

<Salaray>
  <TransactionSalary EmpSL="2" Basic="9860" Grad_pay="4100.00" DA="6282.00" HRA="2094" MA="300.00" Ptax="150.00" pf="2000" Itax="0.00" LIC="0.00" Month_Of="14/Dec/2012" /> 
  <TransactionSalary EmpSL="1" Basic="12560" Grad_pay="4800.00" DA="7812.00" HRA="2604.00" MA="300" Ptax="150.00" pf="2000" Itax="0.00" LIC="0.00" Month_Of="14/Dec/2012" /> 
  <TransactionSalary EmpSL="4" Basic="11850" Grad_pay="4800.00" DA="7493.00" HRA="2498.00" MA="300" Ptax="150.00" pf="2000" Itax="0.00" LIC="0.00" Month_Of="14/Dec/2012" /> 
  </Salaray>',

It shows ..

Msg 8115, Level 16, State 8, Procedure sp_Insert_Monthly_Salary_Req,
Line 26
Arithmetic overflow error converting nvarchar to data type numeric.
Msg 16917, Level 16, State 2, Procedure sp_Insert_Monthly_Salary_Req, Line 27
Cursor is not open.
Msg 16917, Level 16, State 1, Procedure sp_Insert_Monthly_Salary_Req, Line 47
Cursor is not open.

  • 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-06-15T23:42:14+00:00Added an answer on June 15, 2026 at 11:42 pm

    Given an input XML, you can use this simple XQuery statement to “shred” the XML into relational rows and columns – just do a simple INSERT INTO ..... and you’re done. No messy cursor nor OPENXML stuff needed…

    DECLARE @input XML = '<Salaray>
      <TransactionSalary 
        EmpSL="2" Basic="9860" Grad_pay="4100.00" DA="6282.00" HRA="2094" MA="300.00" Ptax="150.00" pf="2000" 
        Itax="0.00" LIC="0.00" Month_Of="14/Dec/2012" /> 
      <TransactionSalary EmpSL="1" Basic="12560" Grad_pay="4800.00" DA="7812.00" HRA="2604.00" MA="300" Ptax="150.00" pf="2000" Itax="0.00" LIC="0.00" Month_Of="14/Dec/2012" /> 
      <TransactionSalary EmpSL="4" Basic="11850" Grad_pay="4800.00" DA="7493.00" HRA="2498.00" MA="300" Ptax="150.00" pf="2000" Itax="0.00" LIC="0.00" Month_Of="14/Dec/2012" /> 
      </Salaray>'
    
    /* just add this INSERT INTO statement when you're confident the SELECT returns the right data! 
    INSERT INTO [Monthly_Salary_Statement]([Emp_SL], [Basic], [Grad_pay], [DA], [HRA], [MA], [Ptax], [Itax], [pf],  [LIC], [Month_Of])
    */
     SELECT
        Emp_SL = XTbl.TSal.value('@EmpSL', 'int'),
        [Basic] = XTbl.TSal.value('@Basic', 'decimal(10,2)'),
        Grad_pay = XTbl.TSal.value('@Grad_pay', 'decimal(6,2)'),
        DA = XTbl.TSal.value('@DA', 'decimal(6,2)'),
        HRA = XTbl.TSal.value('@HRA', 'decimal(6,2)'),
        MA = XTbl.TSal.value('@MA', 'decimal(6,2)'),
        Ptax = XTbl.TSal.value('@Ptax', 'decimal(6,2)'),
        Itax = XTbl.TSal.value('@Itax', 'decimal(6,2)'),
        pf = XTbl.TSal.value('@pf', 'decimal(6,2)'),
        LIC = XTbl.TSal.value('@LIC', 'decimal(6,2)'),
        Month_Of = XTbl.TSal.value('@Month_Of', 'datetime')
      FROM
        @input.nodes('/Salaray/TransactionSalary') AS XTbl(TSal)
    

    Also: mind you, you have values like 12560 for your Basic attribute – those will NOT fit into a decimal(6,2) – that’s 6 digits total, 2 of which after the comma – which also means: only 4 digits before the comma – not enough to hold 12560. I used decimal(10,2) instead – that works.

    Gives me output of:

    enter image description here

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

Sidebar

Related Questions

ALTER PROCEDURE [dbo].[AmendInsertDuplicateFields] (@ReportID varchar(50)) AS BEGIN DECLARE @NewReportID VARCHAR(50) SET @NewReportID = NEWID()
ALTER PROCEDURE [dbo].[test] @tour int, @tourname varchar(50) OUTPUT, @tourdepartures varchar(50) OUTPUT AS BEGIN --
I've created the following stored procedure: ALTER PROCEDURE [dbo].[ExampleSP] ( @SearchText NVARCHAR(4000), @ID INT
I am writing a SP in SQL server ALTER PROCEDURE [dbo].[spAddUserBadge] AS BEGIN INSERT
Take a look at this SP. ALTER PROCEDURE [dbo].[sp_GetRecTitleVeh] AS BEGIN select a.StockNo, c.ClaimNo,
I Create this stored procedure ALTER PROCEDURE [dbo].[Stock_Master_Sp] @common nvarchar(1)='', @PK_ID int=0, @FK_StoneCategory_Master int=0,
I have this stored procedure in my database: ALTER PROCEDURE [dbo].[sp_FTSearchLocation] @SearchFor nvarchar(200) =
ALTER PROCEDURE [dbo].[GetDocumentsAdvancedSearch] @SDI CHAR(10) = NULL ,@Client CHAR(4) = NULL ,@AccountNumber VARCHAR(20) =
ALTER PROCEDURE [dbo].[GetTimeSheetsAttendance] @WhereClause varchar AS EXEC ('Select vwEmployeeList.ID,vwEmployeeList.Code, tbGNClient.FName + '' '' +
Hi I have a Stored Procedure ALTER PROCEDURE [dbo].[usp_EP_GetTherapeuticalALternates] ( @NDCNumber CHAR(11) , @patientid

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.