Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8595531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:27:25+00:00 2026-06-12T00:27:25+00:00

Below is a trigger used to capture updates/inserts on an SQL table. I cannot

  • 0

Below is a trigger used to capture updates/inserts on an SQL table. I cannot figure out why, but whenever an update is done, I get the error message Conversion failed when converting date and/or time from character string. Here is the structure of the Transaction Log table:

CREATE TABLE [dbo].[TransactionLog](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [TransactionDate] [datetime] NOT NULL,
    [Operator] [varchar](35) NOT NULL,
    [TableName] [varchar](50) NOT NULL,
    [Action] [char](1) NOT NULL,
    [TableString] [nvarchar](255) NOT NULL,
    [UserId] [char](6) NULL,
 CONSTRAINT [PK_TransactionLog] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]

Here is the table being updated:

CREATE TABLE [dbo].[AgentContEd](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [sNumber] [int] NOT NULL,
    [StateCode] [char](3) NOT NULL,
    [CourseCode] [char](6) NOT NULL,
    [DateTaken] [date] NOT NULL,
    [ExpirationDate] [date] NULL,
    [CourseHours] [smallint] NOT NULL,
    [Method] [varchar](15) NULL,
    [LastChangeOperator] [char](8) NOT NULL,
    [LastChangeDate] [datetime] NOT NULL,
    [ControlId] [int] NULL,
 CONSTRAINT [PK_AgentContEd] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]

And here is the trigger that’s causing the headache…

BEGIN
    INSERT INTO dbo.TransactionLog 
    (
        TransactionDate, 
        Operator, 
        TableName, 
        Action, 
        TableString, 
        UserId
    )
    SELECT 
        LastChangeDate,
        'Op',
        @tableName,
        @action,
        CAST(
          'ID:'             + CAST(ISNULL(Id,             'NULL') as char(4))
        + ' SymNum:'        + CAST(ISNULL(sNumber,  'NULL') as char(10))
        + ' StateCode:'     + ISNULL(StateCode,           'NULL')
        + ' DateTaken:'     + CAST(ISNULL(DateTaken,      'NULL') as nvarchar(9))
        + ' ExpDate:'       + CAST(ISNULL(ExpirationDate, 'NULL') as nvarchar(9))
        + ' CourseCode:'    + ISNULL(CourseCode,          'NULL')
        + ' Hours:'         + CAST(ISNULL(CourseHours,    'NULL')  as char(3))
        + ' Mthd:'          + ISNULL(Method,              'NULL')
        As char(255)), 
        LastChangeOperator
    FROM inserted
END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:27:27+00:00Added an answer on June 12, 2026 at 12:27 am

    Try

        + ' DateTaken:'     + ISNULL(CAST(DateTaken as varchar(9)),      'NULL')
        + ' ExpDate:'       + ISNULL(CAST(ExpirationDate as varchar(9)), 'NULL') 
    

    I used varchar as it seems pointless to use nvarchar if you are going to be casting the string to char at the end anyway.

    Also you probably need to use CONVERT with a style instead of CAST to store something useful. SELECT CAST(getdate() as nvarchar(9)) returns Sep 28 20 for me.

    A list of formats is here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table trigger like below: CREATE OR REPLACE TRIGGER PAT_BUR_DOB_TRG BEFORE UPDATE
I am newbie in SQL.I am reading Triggers created two trigger on a table.Below
I'm trying to set up a MySQL trigger, but I can't figure out how
I have the below SQL Trigger on a SQL 2005 box that is supposed
I have below trigger ALTER TRIGGER [dbo].[DeleteUserData] ON [dbo].[site_users] AFTER DELETE AS BEGIN SET
The trigger below is delaying my insert response. How can I prevent this? create
My issue is that the trigger detailed below seems to execute correctly except for
I'm trying to work out the ControlTemplate.Triggers in the Style below, and I haven't
I used the code below when initialising my sliders: //Gets the corresponding slider value,
Can jQuery UI be used with web.py? With jQuery and web.py, you can trigger

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.