[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2178
  • Last Modified:

SQL Server 2005 insert trigger

SQL Server 2005 - I'm trying to update a column as the user inserts into the db.  This is my first SQL Server trig and I keep getting a syntax error near 'BEGIN'.  Any ideas???
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
CREATE TRIGGER trg_New_Trigger
   ON  dbo.Table1
   FOR INSERT AS UPDATE
 
BEGIN
 
		SET NOCOUNT ON;
 
UPDATE dbo.Table1
SET Target_Column = (Select substring(cast(getdate() AS CHAR(11)),10,2) + cast(ID_Field AS CHAR(10))
                       From inserted)
WHERE Table1.RowID IN (SELECT RowID FROM inserted)
END
GO

Open in new window

0
stang1
Asked:
stang1
1 Solution
 
chapmandewCommented:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
CREATE TRIGGER trg_New_Trigger
   ON  dbo.Table1
   FOR INSERT,  UPDATE
 AS
BEGIN
 
                SET NOCOUNT ON;
 
UPDATE dbo.Table1
SET Target_Column = (Select substring(cast(getdate() AS CHAR(11)),10,2) + cast(ID_Field AS CHAR(10))
                       From inserted)
WHERE Table1.RowID IN (SELECT RowID FROM inserted)
END
GO
0
 
stang1Author Commented:
I think you answered the question - thanks!  I still get: Msg 207, Level 16, State 1, Procedure trg_Update_Offer_Ref_ID_Yr, Line 16
Invalid column name 'ROWID'.  Do we DECLARE a rowid in SQL Server 2005?  I'll see if I can debug it.  Thanks Again.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now