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

  • SEARCH
  • Home
  • 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 7808263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:05:27+00:00 2026-06-02T03:05:27+00:00

I have to sync changes done in MSSQL with a remote MySQL database. The

  • 0

I have to sync changes done in MSSQL with a remote MySQL database. The changes to be synced are adding invoices and users to the system. The remote server is not expected to be always reachable so I’m trying to set up a kind of log table for storing changes done in MSSQL.

Here is a fully working trigger for that:

CREATE TRIGGER [dbo].[dokument_insert]
   ON [dbo].[dokument]
   AFTER INSERT
AS 
BEGIN
    SET NOCOUNT ON;
    INSERT INTO [bcg_ekodu].[dbo].[sync_stack] (event,sql, table_name, import_priority)
        SELECT 
            'INSERT',
            'INSERT INTO bills SET
                date = "'+CONVERT(VARCHAR(19),dok_kuup,120)+'", 
                total = "'+CAST(kokkusum AS nvarchar)+'",
                number = "'+RTRIM(dok_nr)+'", 
                created = "'+CONVERT(VARCHAR(19),savetime,120)+'", 
                rounded = "'+CAST(ymardus AS nvarchar)+'",
                currency = "'+CAST(valuuta AS nvarchar)+'", 
                due_date = "'+CONVERT(VARCHAR(19),tasupaev,120)+'", 
                pk_joosep = "'+CAST(dok_kood AS nvarchar)+'",
                joosep_hankija = "'+CAST(hankija AS nvarchar)+'";
             UPDATE
                bills, users, companies 
             SET 
                bills.user_id = users.id,
                bills.imported = NOW()
             WHERE
                bills.imported IS NULL
                AND companies.id = users.company_id
                AND companies.pk_joosep = 10
                AND bills.user_id = users.pk_joosep',
            'bills',
            '200'
        FROM inserted
END

It inserts a row into ‘sync_stack’ table every time a row is inserted to ‘dokument’ table. The ‘sql’ column will contain an SQL to create the same kind of row in another (MySQL) database.

But this trigger is not working:

CREATE TRIGGER [dbo].[klient_insert]
   ON [dbo].[klient]
   AFTER INSERT
AS 
BEGIN
    SET NOCOUNT ON;
    INSERT INTO [bcg_ekodu].[dbo].[sync_stack] (event,sql, table_name, import_priority)
        SELECT 
            'INSERT',
            'INSERT INTO users SET
                username =10'+CAST(kl_kood as nvarchar)+',
                password = NULL,
                name ="'+LTRIM(RTRIM(kl_nimi))+'",  
                email ="'+CAST(LTRIM(RTRIM(kl_email)) as nvarchar)+'",  
                reference_no ="'+CAST(LTRIM(RTRIM(kl_viide)) as nvarchar)+'",   
                phone ="'+CAST(LTRIM(RTRIM(kl_tel1)) as nvarchar)+'",   
                logins ="'+CAST(0 as nvarchar)+'",  
                last_login = NULL,  
                created ="'+CONVERT(VARCHAR(19),savetime,120)+'",   
                updated = NULL, 
                deleted ="0",   
                address ="'+CAST(LTRIM(RTRIM(kl_aadr1)) as nvarchar)+'",    
                pk_joosep ="'+CAST(kl_kood as nvarchar)+'"',
            'users',
            '210'
        FROM inserted
END

While the execution of the above SQL to create that trigger completes just fine, when I try to insert some rows to the ‘triggered’ table, I get the following error:

No row was updated.

The data in row 175 was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: Cannot insert the value NULL into column 'sql', table 'mydb.dbo.sync_stack'; column does not allow nulls. INSERT fails.

The statement has been terminated.

Correct the errors and retry or press ESC to cancel the change(s).
  • If I delete this trigger, this error does not occur.
  • If I insert just plain text for ‘sql’ column, it works as expected.
  • If I use any field from the inserted row, even just a text field, it fails again.
  • If I allow NULL values in ‘sql’ column, inserting rows succeeds but I get a NULL value in ‘sql’ column.

How to make the second trigger work as expected, too?

  • 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-02T03:05:28+00:00Added an answer on June 2, 2026 at 3:05 am

    Concatenating any value to NULL is NULL:

    select 'test' + NULL
    

    Results in null, you should use something like that for your columns:

    select isnull(column, '')
    

    This would result in an empty string.

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

Sidebar

Related Questions

I have one folder synced between two computers (using one of online sync tools).
I have Aptana Studio 3 set up using the Deployment Wizard to sync changes
I have a local mysql db and a production mysql db. I make changes
I have project on the remote server and a copy of it on my
I have a not-so-small class under development (that it changes often) and I need
I have a need to sync auto_increment fields between two tables in different databases
I have a desktop application that will 'sync' with an iPhone application. The sync
I have a web application that I want to sync with Flickr. I don't
I have a machine which uses an NTP client to sync up to internet
I have problem with keeping my model (represented as List) in sync with a

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.