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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:19:09+00:00 2026-06-12T22:19:09+00:00

This gave an error Msg 156, Level 15, State 1, Procedure Trig_Insert_Serials_Null, Line 30

  • 0

This gave an error

Msg 156, Level 15, State 1, Procedure Trig_Insert_Serials_Null, Line 30
Incorrect syntax near the keyword ‘INSERT’.

Table structure:

Serials (CurrencyId, DivisionId, BranchId, NewSerialNumber, Display, TypeId)

I want to change 0 to null in (CurrencyId, DivisionId, BranchId).

CREATE TRIGGER Trig_Insert_Serials_Null
   ON  Serials
   INSTEAD OF INSERT   
AS 
BEGIN

DECLARE @currencyId int;
DECLARE @branchId int;
DECLARE @divisionId int;

SELECT @currencyId = INSERTED.CurrenceyId FROM INSERTED;
SELECT @branchId = INSERTED.BranchId FROM INSERTED;
SELECT @divisionId = INSERTED.DivisionId FROM INSERTED;

IF @currencyId = 0 
    SET @currencyId = NULL;
END

IF @branchId = 0 
    SET @branchId = NULL;
END

IF @divisionId = 0 
    SET @divisionId = NULL;
END


INSERT INTO Serials (CurrenceyId,DivisionId,BranchId,NewSerialNumber,
                         Display, TypeId)
VALUES (INSERTED.CurrenceyId,INSERTED.DivisionId, INSERTED.BranchId,
         INSERTED.NewSerialNumber, INSERTED.Display,INSERTED.TypeId)

END
GO
  • 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-12T22:19:10+00:00Added an answer on June 12, 2026 at 10:19 pm

    You are assuming that the trigger is fired once per row – this is wrong.

    The trigger is fired once per batch and could be fired for a single INSERT statement that insert 50 rows.

    Therefore, your statements like this:

    SELECT @currencyId = INSERTED.CurrenceyId FROM INSERTED;
    

    will fail miserably.

    You need to re-write your trigger to take this into account – the Inserted table can contain one or multiple rows – you cannot just plainly assume it’s always a single row.

    Basically, you need to do something like this:

     INSERT INTO Serials (CurrenceyId, DivisionId, BranchId, NewSerialNumber, Display, TypeId)
        SELECT
           CASE i.CurrenceyId WHEN 0 THEN NULL ELSE i.CurrenceyId END,
           CASE i.DivisionId WHEN 0 THEN NULL ELSE i.DivisionId END,
           CASE i.BranchId WHEN 0 THEN NULL ELSE i.BranchId END,
           i.NewSerialNumber, i.Display, i.TypeId
        FROM Inserted i
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've loaded a .exe and it gave this error: Microsoft (R) Windows Debugger Version
This is follow up on Mono xbuild error CS1548 - key file has incorrect
I followed the following procedure: 1) $ sudo pip install psycopg2 This gave me
In Jquery Template website they gave this example.( http://api.jquery.com/jQuery.template/ ) <script> var movies =
This StackOverflow question gave me food for thought on what is a good structure
A friend gave me this code snippet in Clojure (defn sum [coll acc] (if
I desined a button in Blend, which gave me this xaml in after the
This supposedly easy task gave me some headache. I simply want to let the
This question is fairly fundamental.I gave a simple and straighfoward test on my cygwin:
In this question , Codygman gave an answer that some operators offer a way

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.