Solved

Error creating SQL2008 trigger

Posted on 2013-11-08
2
217 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

747 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

14 Experts available now in Live!

Get 1:1 Help Now