Collation issue when using merge

Ron 20 Reputation points
2024-10-31T06:29:13.7266667+00:00

Trying to load data from TableA (Source) to TableB (Target) by Merge query.

One of the columns in TableA is Latin1_General_CS_AS, while the target column in TableB is Latin1_General_CI_AS.

Should I firstly change collation setting in Table B before running the merge query?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,982 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,654 questions
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 27,961 Reputation points
    2024-10-31T06:50:22.9833333+00:00

    Hi @Ron

    Should I firstly change collation setting in Table B before running the merge query?

    Yes, you can alter the column definition like this:

    ALTER TABLE TableA ALTER COLUMN Column1 varchar(100) COLLATE Latin1_General_CI_AS;
    

    Also, you can just CAST the collation in the merge statement like this:

    MERGE INTO TableB AS target 
    USING TableA AS source
    ON target.Column1 COLLATE Latin1_General_CI_AS = source.Column1 COLLATE Latin1_General_CI_AS
    

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.