Solved

Error creating SQL2008 trigger

Posted on 2013-11-08
2
220 Views
Last Modified: 2013-11-26
I'm trying to create a trigger but am getting an error when it runs on the initial create.  I actually am simply modifying an existing trigger from another database with much of the same data but no errors.

The error is
Msg 273, Level 16, State 1, Procedure tr_trnUPS_EndOfDay_Insert, Line 13
Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.


The code is

INSERT INTO DYNAMICS_EXT.dbo.trnUPS_EndOfDay_Detail
(      
      login_Name
    ,user_name
    ,spid
    ,hostname
    ,trnAction
      ,get_date
      , OrderNumber
      , Weight
      , MasterTrackingNumber
      , TrackingNumber
      , Cost
      , DateofShipment
      , ShipVia
      , CustomerName
      , Country
      , State
      , AccountNumber
      , TaxID
      , PostalCode
      , TS
      , Host
)
      
SELECT
      (system_user)login_Name
    ,(user)user_name
    ,(@@spid)spid
    ,(host_name())hostname
    ,('Insert')trnAction
      ,(getdate()) as get_date      
      , OrderNumber
      , Weight
      , MasterTrackingNumber
      , TrackingNumber
      , Cost
      , DateofShipment
      , ShipVia
      , CustomerName
      , Country
      , State
      , AccountNumber
      , TaxID
      , PostalCode
      , TS
      , Host
FROM INSERTED
0
Comment
Question by:jdr0606
2 Comments
 
LVL 6

Assisted Solution

by:RaithZ
RaithZ earned 250 total points
ID: 39634615
One of the columns has a type of "TimeStamp" which you can't put specific values into since it is automatically populated when a row is inserted.  So you would need to find out what column that is an exclude it from the insert command.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 39640269
INSERT INTO DYNAMICS_EXT.dbo.trnUPS_EndOfDay_Detail
(      
      login_Name
    ,user_name
    ,spid
    ,hostname
    ,trnAction
      ,get_date
      , OrderNumber
      , Weight
      , MasterTrackingNumber
      , TrackingNumber
      , Cost
      , DateofShipment
      , ShipVia
      , CustomerName
      , Country
      , State
      , AccountNumber
      , TaxID
      , PostalCode
      , TS
      , Host
)
     
SELECT
      (system_user)login_Name
    ,(user)user_name
    ,(@@spid)spid
    ,(host_name())hostname
    ,('Insert')trnAction
      ,(getdate()) as get_date      
      , OrderNumber
      , Weight
      , MasterTrackingNumber
      , TrackingNumber
      , Cost
      , DateofShipment
      , ShipVia
      , CustomerName
      , Country
      , State
      , AccountNumber
      , TaxID
      , PostalCode
      , DEFAULT
      , Host
FROM INSERTED
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

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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

777 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