Solved

SQL 2005 E, INSTEAD OF UPDATE Trigger..

Posted on 2006-11-13
3
1,579 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
3 Comments
 
LVL 142

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

816 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now