Hello all,We have to synchronize data between databases with different collations, and I'm not sure what is the preferred syntax for the update statement. Could you give me your opinions?First, a sample environment:-- create tables for testingCREATE TABLE #temp1 ( col1 NVARCHAR(10) COLLATE Latin1_General_BIN , col2 NVARCHAR(30) COLLATE Latin1_General_BIN )GOCREATE TABLE #temp2 ( col1 NVARCHAR(10) COLLATE Latin1_General_CI_AS , col2 NVARCHAR(30) COLLATE Latin1_General_CI_AS )GO-- insert sample dataINSERT INTO #temp1 ( col1 , col2 )SELECT 'test1', 'This is test row 1'UNION ALLSELECT 'test2', 'This is test row 2'UNION ALLSELECT 'test3', 'This is test row 3'GOINSERT INTO #temp2 ( col1 , col2 )SELECT 'test1', 'sample data item 1'UNION ALLSELECT 'test2', 'sample data item 2'UNION ALLSELECT 'test3', 'sample data item 3'GO
Now, the update statement:-- updateUPDATE t2SET t2.col2 = t1.col2FROM #temp1 t1 , #temp2 t2WHERE t1.col1 = t2.col1
This of course fails, saying "Cannot resolve collation conflict for equal to operation." So I need to use the collation name in my WHERE clause to compare columns. The question is, which collation name should I use?WHERE t1.col1 = t2.col1 COLLATE Latin1_General_BINORWHERE t1.col1 = t2.col1 COLLATE Latin1_General_CI_AS
...and WHY should I use one over the other? Or does it matter at all?Since this will be a "synchronization" of data, I have to do this in both directions (with of course some other criteria to identify which records to sync which way). If the source, or the target, collation should be specified when doing an update, I would like to know which is preferred and why.Thanks for your help!Regards,Daniel-- return data to verify the updateSELECT t1.col1 , t1.col2 , t2.col2FROM #temp1 t1 , #temp2 t2WHERE t1.col1 = t2.col1 COLLATE Latin1_General_BIN-- clean upDROP TABLE #temp1GODROP TABLE #temp2GO