Solved

SQL 2005 E, INSTEAD OF UPDATE Trigger..

Posted on 2006-11-13
3
1,581 Views
Last Modified: 2008-02-01
I havent been fumbling with triggers in years, and wonder whats wrong with this trigger?

I get "invalid object "inserted" in VS2005.

Anyone?

#########################################################
CREATE TRIGGER Trigger1
ON dbo.Site_Page
INSTEAD OF UPDATE
AS
IF EXISTS (SELECT  PageID FROM INSERTED ins WHERE SubTo = 1)

      BEGIN
      SET NOCOUNT ON
      UPDATE    Site_Page
      SET              SubTo = 1, PageName = insPageName, MenuName = ins.MenuName, SortOrder = ins.SortOrder, ViewPage = ins.ViewPage
      FROM         inserted AS ins CROSS JOIN
                            Site_Page
      END

#########################################################
0
Comment
Question by:mattisflones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 17928667
the code looks fine, how do you try to run it?
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 17928694
a "." was missing in insPageName

CREATE TRIGGER Trigger1
ON dbo.Site_Page
INSTEAD OF UPDATE
AS
IF EXISTS (SELECT  PageID FROM INSERTED ins WHERE SubTo = 1)

     BEGIN
     SET NOCOUNT ON
     UPDATE    Site_Page
     SET              SubTo = 1, PageName = ins.PageName, MenuName = ins.MenuName, SortOrder = ins.SortOrder, ViewPage = ins.ViewPage
     FROM         inserted AS ins CROSS JOIN
                           Site_Page
     END
0
 
LVL 15

Author Comment

by:mattisflones
ID: 17929181
The missing "." was not the problem.. it was a copy error.

I tested in VS2005s queryboilder, and that seems to be a little sucky... but thanks for making me think!

This worked as intended!

CREATE TRIGGER TriggerUpd
ON dbo.Site_Page
INSTEAD OF UPDATE
AS
IF EXISTS (SELECT  PageID FROM INSERTED ins WHERE SubTo = 1)

     BEGIN
     SET NOCOUNT ON
     UPDATE    Site_Page
     SET              SubTo = null, PageName = ins.PageName, MenuName = ins.MenuName, SortOrder = ins.SortOrder, ViewPage = ins.ViewPage
     FROM         inserted AS ins CROSS JOIN
                           Site_Page WHERE ins.PageID = Site_Page.PageID
     END
     ELSE
     BEGIN
     SET NOCOUNT ON
     UPDATE    Site_Page
     SET              SubTo = ins.SubTo, PageName = ins.PageName, MenuName = ins.MenuName, SortOrder = ins.SortOrder, ViewPage = ins.ViewPage
     FROM         inserted AS ins CROSS JOIN
                           Site_Page WHERE ins.PageID = Site_Page.PageID
     END
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question