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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:34:50+00:00 2026-05-15T13:34:50+00:00

I have a trigger that is used for auditing inserted, updated and deleted rows.

  • 0

I have a trigger that is used for auditing inserted, updated and deleted rows. I am having an issue with acquiring the Old Values and New Values from the trigger. The trigger utilizes a loop to insert all values of any row that has been altered in any way (inserted, updated, deleted). However, my code is not returning the values but instead the column names as the values.

Here is part of my code:

SELECT @COLNAME = NAME 
FROM SYSCOLUMNS 
WHERE COLID = @FIELD AND
    ID = (SELECT ID FROM SYSOBJECTS WHERE NAME = 'FIN_HOTEL_DTL_TYPE') 
SELECT @OLDVAL = SUBSTRING(@COLNAME, 2, LEN(@COLNAME)) FROM DELETED 
SELECT @NEWVAL = SUBSTRING(@COLNAME, 2, LEN(@COLNAME)) FROM INSERTED 
SELECT @MODBY = MODIFIED_BY FROM INSERTED 
SELECT @MODDT = MODIFIED_DATETIME FROM INSERTED 
  • 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-15T13:34:50+00:00Added an answer on May 15, 2026 at 1:34 pm

    T-SQL is just a different world.

    Your code is doing exactly what you have told it to do. @ColName is not a reference to a column object, but a variable holding a string value which you have loaded with the name of a column.

    I suggest that you look at an example. Read the whole thing if you wish, but if you are in a hurry, drop down to the phrase CREATE TRIGGER Audit.

    Also, take the time to do this with set based logic – as in the example. Harness the power and performance of the DBMS by making use of T-SQL and throwing loose the bonds of row by row coding. No really. Coded loops = poor performance. If needed, the DBMS will implement loops ( or however it wishes ) in the background.

    Good luck!


    I was trying to find this link earlier. I believe that this posting by Paul Nielsen is pretty close to what you want.

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

Sidebar

Ask A Question

Stats

  • Questions 468k
  • Answers 468k
  • 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 I have been receiving the jScrollPane Google Group messages recently,… May 16, 2026 at 2:18 am
  • Editorial Team
    Editorial Team added an answer The following should work: <table style="width:300px;table-layout:fixed"></table> May 16, 2026 at 2:18 am
  • Editorial Team
    Editorial Team added an answer <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <input type="submit" value="Let's see what… May 16, 2026 at 2:18 am

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.