• Sean Lange (9/19/2012)


    Hi and welcome to SSC!!! It is somewhat unclear exactly what you are trying to do but in your trigger you are not referencing the insert virtual table. http://msdn.microsoft.com/en-us/library/ms191300.aspx

    If you need specific help with coding your trigger we would need some more details. See the first link in my signature for best practices when posting questions.

    HI thank you

    for the response I will be sure to attempt to Post in the correct format .

    This is more a learning exercise for me , to try and broaden what little I know.

    This is probably why it didn't come out quite clear

    What I am trying to achieve is , creating a trigger that will do a update and a insert simultaneously into secondary table when data is changed in the Primary.

    I the db that I have I have a main customer and a link customer

    The main customer is designated with a '0' in the MainAccLink field.

    DClink and CLlink are identity columns

    Create table

    CREATE TABLE [dbo].[Client](

    [DCLink] [int] IDENTITY(1,1) NOT NULL,--Is an IDENTITY column on real table

    [Name] [varchar](50) NULL,

    [Post1] [varchar](50) NULL,

    [Post2] [varchar](50) NULL,

    [Post3] [varchar](50) NULL,

    [Post4] [varchar](50) NULL,

    [Post5] [varchar](50) NULL,

    [PostPC] [varchar](50) NULL,

    [DCREF] [int] NULL,

    [MainAccLink] [int] NULL

    CREATE TABLE [dbo].[Client2](

    [CLLink] [int] IDENTITY(1,1) NOT NULL,--Is an IDENTITY column on real table

    [Name] [varchar](50) NULL,

    [Post1] [varchar](50) NULL,

    [Post2] [varchar](50) NULL,

    [Post3] [varchar](50) NULL,

    [Post4] [varchar](50) NULL,

    [Post5] [varchar](50) NULL,

    [PostPC] [varchar](50) NULL,

    [DCREF] [int] NULL,

    [MainAccLink] [int] NULL

    Insert into Client

    (DCLink,Name,Post1,Post2,Post3,Post4,Post5,PostPC,CREF,MainAccLink)

    select'3','LOUIS PETER','P.O BOX 20800','DURBAN','','','','4000','3','0', UNION ALL

    select'4','BRUCE LYLE FAMILY ','P.O.BOX 557','BALITO','','','','4420','4','0', UNION ALL

    select'5','LOWE GARET S.','18 PARKVIEW DRIVE ','MANORS','TOWN','','','3610','5','0', UNION ALL

    select'6','ANNAMALAI L','PO BOX 6','BRAN CROSS','','','','2164','7','0', UNION ALL

    select'7','CABE COLIN','P.O. BOX 750','WESTVILLE','','','','3630','8','0', UNION ALL

    So those are the Tables

    The Idea is if I edit a record in Client table say the name it must edit the Name in Client2

    and

    If I add to Client it must add to client 2.

    I think the separate scripts in my first post would do it individually

    I want to try to add a trigger on the Client Table so it updates automatically .