Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL 2005 E, INSTEAD OF UPDATE Trigger..

Posted on 2006-11-13
3
Medium Priority
?
1,588 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

876 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