Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error creating SQL2008 trigger

Posted on 2013-11-08
2
Medium Priority
?
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Assisted Solution

by:RaithZ
RaithZ earned 750 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 70

Accepted Solution

by:
Scott Pletcher earned 750 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

610 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