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

The Archive Base Latest Questions

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

I have a trigger that gets inserts and updates to a view. I need

  • 0

I have a trigger that gets inserts and updates to a view. I need to find the columns that are being modified and get the value into the correct table.

INSERT INTO TempTableAttr_Lot(ID, [% Num]) VALUES(3, 24.0)

I am trying to figure out how, in my trigger, to get the value of ID and [% Num] columns. The problem is that there can be 32 different columns that are set in the insert or update, so I want to loop through looking to see if that column is in the ‘inserted’ table.

One problem is that if I use exec or execute, to build a dynamic query, inserted is not in scope for this.

The view is dynamic in that if attributes are added then the view is regenerated by a stored procedure, so I can’t assume what column names are in the view at any given time, it can grow and shrink.

Ideally I would like to do SET @Value = (SELECT i.[@Name] FROM inserted i) But @Name is not a column name, but a variable in my trigger, so when I tried

DECLARE @ValueTable TABLE ( value sql_variant)
INSERT INTO @ValueTable EXECUTE('SELECT i.[' + @Name + '] FROM inserted i')
SET @Value = CONVERT(nvarchar(128), (SELECT DISTINCT * FROM @ValueTable))

this didn’t work as inserted appears to not be in scope.

For the first loop @Name = ‘ID’ and for the second it will be ‘Col2’ which was not inserted, so the value of @Value should be null, and I continue to loop through the possible column names until I finish, and the trigger is processed.

I am calling it a trigger, it is defined as:

CREATE TRIGGER TempTableAttr_LotTrigger 
ON  TempTableAttr_Lot 
INSTEAD OF UPDATE, INSERT

I am testing with an INSERT command at the moment. I realize that when doing an update I may need to look at the ‘deleted’ table.

UPDATE: I am assuming only one row is being inserted at the moment, for my test, to see how to get this to work. This is for an entity-attribute-value database, but I have a view that makes it look relational. When using Integration Service, when the updating is going on, any inserts or updates to the view will call the trigger. I am just trying to understand how to get the information I need so I can update the correct table, with the correct values.

  • 1 1 Answer
  • 1 View
  • 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-11T21:10:19+00:00Added an answer on May 11, 2026 at 9:10 pm

    To get access to the INSERTED table you can do the following.

    SELECT * INTO #MYINSERTED FROM INSERTED
    
    EXEC('SELECT * FROM #MYINSERTED')
    
    DROP TABLE #MYINSERTED
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 131k
  • Answers 131k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The reason for the deadlocks in my setup scenario was… May 12, 2026 at 6:13 am
  • Editorial Team
    Editorial Team added an answer Unfortunately, it doesn't appear solvable. Basically, the xml changes made… May 12, 2026 at 6:13 am
  • Editorial Team
    Editorial Team added an answer I realise this isn't a solution in the programming languages… May 12, 2026 at 6:13 am

Related Questions

I recently started working on a large complex application, and I've just been assigned
I'm having an issue with a trigger that inserts a value into the same
Ok,I'm running a setup with a single master and a number of slaves. All
I've a feeling this might not be possible, but here goes... I've got a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.