Solved

Error creating SQL2008 trigger

Posted on 2013-11-08
2
218 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:
ScottPletcher 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

929 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

11 Experts available now in Live!

Get 1:1 Help Now