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

  • SEARCH
  • Home
  • 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 6711843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:11:21+00:00 2026-05-26T08:11:21+00:00

I am using INSERT Trigger on that table. Once trigger is executed (it update

  • 0

I am using INSERT Trigger on that table. Once trigger is executed (it update the table if a condition is meet), that is where the problem is.

  int records = sc.ExecuteNonQuery(); // works ok if trigger does not update the record

The above code always ruturns -1 if I leave SET NOCOUNT ON; in the stored procedure itself. If I remove it, I get correct result but if trigger does update the record, then wrong result. I sometime get 10 or a different number. My Trigger looks like this

UPDATE students 
    SET status = 'Inactive'

    FROM Inserted i
        INNER JOIN students T2
            ON i.sname = T2.sname
            AND i.id <> t2.id

That means it can return more than one record (esp in test cases). Can someone tell me what is the cure? I am open to use Functions if that solves the problem or any better approach.

Thanks

Adding Insert SP

CREATE PROCEDURE sp_InsertSudent 
    -- Add the parameters for the stored procedure here
    @student_name varchar(25) = null, 
    @status varchar(20) = null,
    @renew varchar(15) = null,
    @edate datetime = null
AS
BEGIN

    --SET NOCOUNT ON;

    insert into students VALUES(@student_name,@status,@renew,@edate)


END
GO

Note: I am looking for an error because the fields are picked from Excel. if any field is in wrong format or empty, the Insert SP will produce error. I must convey that error to the user.

Adding Actual SP

So the whole problem is in the SP. If I remove it, everything works fine. Here is my actual SP

UPDATE CustomerTbl
SET [Account Status] = 'Inactive',
    [End Date] = DateAdd(day,-1,[Supplier End Date]),
    [EnrollmentStatus] = 'Waiting'
WHERE OET.[Account No] = (SELECT [Account No] FROM CustomerTbl WHERE id = @@identity)
  AND id <> @@identity

The logic is the same as above but stated differently. The ExecuteNonQuery oupts the result of this trigger than than the actual storedprocedure, so what is he cure? Can suppress its output somehow.

  • 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-26T08:11:21+00:00Added an answer on May 26, 2026 at 8:11 am

    My own answer (not complete yet). According to MSDN documentation for ExecuteNonQuery

    When a trigger exists on a table being inserted or updated, the return
    value includes the number of rows affected by both the insert or
    update operation and the number of rows affected by the trigger or
    triggers.

    This means I need to modify the trigger itself to accommodate the logic, or even by the fact that when trigger is called, that proves that a record was successful. That means if I get anything greater than 0, that should be assumed as success. Although not solid logic but it will work. SET COUNT ON must be commented for this.

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

Sidebar

Related Questions

I have a table that has a Trigger associated with it for Update, Insert
I have a trigger that executes a function on table insert or update. It
I'm writing a trigger that will do a cross table update, but I can't
I'm using insert-/update triggers to update a second table's column Price . The insert
Using the Northwind sample: I would like to create an insert trigger on the
I'm using INSERT INTO to copy rows of data from one table to another:
I'm trying to do an Insert operation using iBatis. INSERT INTO SCHEMA.TABLE (FIELD1, FIELD2,
I'm trying to write a table trigger which queries another table that is outside
I've got the following trigger; CREATE TRIGGER trFLightAndDestination ON checkin_flight AFTER INSERT,UPDATE AS BEGIN
I have a trigger that is fire on inserting a new record in table

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.