Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. dbo Trigger

dbo Trigger

Scheduled Pinned Locked Moved Database
databasesysadminquestionannouncement
6 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zeusToronto
    wrote on last edited by
    #1

    Hi, I am trying to add a trigger on insert event on a table in SQL_Express. ALTER trigger [dbo].[TR_Insert_New_Pair] on [dbo].[Vendors] FOR INSERT AS DECLARE @ACCPACID varchar(12), @VNAME varchar(60) SELECT @ACCPACID = (SELECT ACCPACVENDORID from inserted), @VNAME = ( SELECT VENDNAME FROM [ONT-ACCOUNTING].EXTDAT.DBO.APVEN --[ont-dell] is a linked server WHERE LTRIM(RTRIM(VENDORID)) = LTRIM(RTRIM(@ACCPACID)) ) UPDATE dbo.Vendors SET VENDNAME = @VNAME WHERE LTRIM(RTRIM(ACCPACVENDORID)) = ltrim(rtrim(@ACCPACID)) --This part works great (I've tested) SELECT VENDNAME FROM [ONT-ACCOUNTING].EXTDAT.DBO.APVEN --[ont-dell] is a linked server WHERE LTRIM(RTRIM(VENDORID)) = LTRIM(RTRIM(@ACCPACID)) Is there something I am not seeing ???? Thanks Kirill

    A 1 Reply Last reply
    0
    • Z zeusToronto

      Hi, I am trying to add a trigger on insert event on a table in SQL_Express. ALTER trigger [dbo].[TR_Insert_New_Pair] on [dbo].[Vendors] FOR INSERT AS DECLARE @ACCPACID varchar(12), @VNAME varchar(60) SELECT @ACCPACID = (SELECT ACCPACVENDORID from inserted), @VNAME = ( SELECT VENDNAME FROM [ONT-ACCOUNTING].EXTDAT.DBO.APVEN --[ont-dell] is a linked server WHERE LTRIM(RTRIM(VENDORID)) = LTRIM(RTRIM(@ACCPACID)) ) UPDATE dbo.Vendors SET VENDNAME = @VNAME WHERE LTRIM(RTRIM(ACCPACVENDORID)) = ltrim(rtrim(@ACCPACID)) --This part works great (I've tested) SELECT VENDNAME FROM [ONT-ACCOUNTING].EXTDAT.DBO.APVEN --[ont-dell] is a linked server WHERE LTRIM(RTRIM(VENDORID)) = LTRIM(RTRIM(@ACCPACID)) Is there something I am not seeing ???? Thanks Kirill

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      zeusToronto wrote:

      Is there something I am not seeing ????

      I'm not seeing your question. What the problem and error message?

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      Z 1 Reply Last reply
      0
      • A Ashfield

        zeusToronto wrote:

        Is there something I am not seeing ????

        I'm not seeing your question. What the problem and error message?

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

        Z Offline
        Z Offline
        zeusToronto
        wrote on last edited by
        #3

        I am sorry, when Insert happens trigger does not seem to update the line. This trigger has other parts to it which seem to work just fine.

        A 1 Reply Last reply
        0
        • Z zeusToronto

          I am sorry, when Insert happens trigger does not seem to update the line. This trigger has other parts to it which seem to work just fine.

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          Have you checked that the value from the linked server is being populated? Have you tried the simple test of hard coding a value into @Vname and seeing if that works? I have a sneaky feeling that linked servers don't work from triggers, but I'm not certain.

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          Z 1 Reply Last reply
          0
          • A Ashfield

            Have you checked that the value from the linked server is being populated? Have you tried the simple test of hard coding a value into @Vname and seeing if that works? I have a sneaky feeling that linked servers don't work from triggers, but I'm not certain.

            Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

            Z Offline
            Z Offline
            zeusToronto
            wrote on last edited by
            #5

            Ashfield this is exactly how I've tested everything. Values do come from linked server, and when I hard code the value trigger seem to update it just fine. I even went as far as changing the trigger to update from the local table (LOCAL SQL Table) and it works. The only issue I am having is when update happens from a linked server.

            A 1 Reply Last reply
            0
            • Z zeusToronto

              Ashfield this is exactly how I've tested everything. Values do come from linked server, and when I hard code the value trigger seem to update it just fine. I even went as far as changing the trigger to update from the local table (LOCAL SQL Table) and it works. The only issue I am having is when update happens from a linked server.

              A Offline
              A Offline
              Ashfield
              wrote on last edited by
              #6

              zeusToronto wrote:

              Values do come from linked server

              Is that tested from within the trgger or just as a piece of sql? Based on your reply, if you hard code it or get the values from a local table it works, the only time it doesn't is when you get the values from a linked server in the trigger. The only cnclusion you can draw from this is that the linked server fetch is not working in the trigger.

              Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups