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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:11:40+00:00 2026-05-10T15:11:40+00:00

Here’s something I haven’t been able to fix, and I’ve looked everywhere . Perhaps

  • 0

Here’s something I haven’t been able to fix, and I’ve looked everywhere. Perhaps someone here will know!

I have a table called dandb_raw, with three columns in particular: dunsId (PK), name, and searchName. I also have a trigger that acts on this table:

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO  ALTER TRIGGER [dandb_raw_searchNames]     ON [dandb_raw]     FOR INSERT, UPDATE     AS  SET NOCOUNT ON    select dunsId, name into #magic from inserted          UPDATE dandb             SET dandb.searchName = company_generateSearchName(dandb.name)             FROM (select dunsId, name from #magic) i             INNER JOIN dandb_raw dandb                 on i.dunsId = dandb.dunsId           --Add new search matches         SELECT c.companyId, dandb.dunsId             INTO #newMatches             FROM dandb_raw dandb             INNER JOIN (select dunsId, name from #magic) a                 on a.dunsId = dandb.dunsId             INNER JOIN companies c                 ON dandb.searchName = c.searchBrand                 --avoid url matches that are potentially wrong                 AND (lower(dandb.url) = lower(c.url)                     OR dandb.url = ''                     OR c.url = ''                     OR c.url is null)           INSERT INTO #newMatches (companyId, dunsId)         SELECT c.companyId, max(dandb.dunsId) dunsId             FROM dandb_raw dandb             INNER JOIN                 (                     select                     case when charindex('/',url) <> 0 then left(url, charindex('/',url)-1)                     else url                     end urlMatch, * from companies                 ) c                 ON dandb.url = c.urlMatch             where subsidiaryOf = 1 and isReported = 1 and dandb.url <> ''                 and c.companyId not in (select companyId from #newMatches)             group by companyId             having count(dandb.dunsId) = 1          UPDATE cd             SET cd.dunsId = nm.dunsId             FROM companies_dandb cd             INNER JOIN #newMatches nm                 ON cd.companyId = nm.companyId GO 

The trigger causes inserts to fail:

insert into  [dandb_raw](dunsId, name)     select 3442355, 'harper'     union all     select 34425355, 'har 466per' update [dandb_raw] set name ='grap6767e' 

With this error:

Msg 213, Level 16, State 1, Procedure companies_contactInfo_updateTerritories, Line 20 Insert Error: Column name or number of supplied values does not match table definition. 

The most curious thing about this is that each of the individual statements in the trigger works on its own. It’s almost as though inserted is a one-off table that infects temporary tables if you try to move inserted into one of them.

So what causes the trigger to fail? How can it be stopped?

  • 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. 2026-05-10T15:11:40+00:00Added an answer on May 10, 2026 at 3:11 pm

    I think David and Cervo combined have hit on the problem here.

    I’m pretty sure part of what was happening was that we were using #newMatches in multiple triggers. When one trigger changed some rows, it would fire another trigger, which would attempt to use the connection scoped #newMatches.

    As a result, it would try to, find the table already existed with a different schema, die, and produce the message above. One piece of evidence that would be in favor: Does inserted use a stack style scope (nested triggers have their own inserteds?)

    Still speculating though – at least things seem to be working now!

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

Sidebar

Related Questions

Here's what I want to do: Given a table PeopleOutfit (id int primary key,
Here's the method. I want to know if I am violating any best practices
I have a jquery bug and I've been looking for hours now, I can't
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is an example: I have the generic type called Account. I wish to
Here I have an int x=3; NSLog(@%i, x); How to have it displayed like
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here is my code sample, let me know if it can be further improved?

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.