Solved

SQL 2005 E, INSTEAD OF UPDATE Trigger..

Posted on 2006-11-13
3
1,577 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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

21 Experts available now in Live!

Get 1:1 Help Now