Regular Collation issue but collate statement on join still giving same error - sql

I have the following query:
Update
AEB
Set
[hbs_mailreturned] = 1
from
AccountExtensionBase AEB
Inner Join #IndividualsIDs I1 on
AEB.hbs_organisationid collate SQL_Latin1_General_CP1_CI_AS = I1.hbs_individualid collate SQL_Latin1_General_CP1_CI_AS
It is giving the following error message:
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AI" in the equal to operation.
I don't understand this because I have specifying the collation to use on the join statement. What am I missing here?

I guess this will not create issue which you have applied on your columns,
AEB.hbs_organisationid collate SQL_Latin1_General_CP1_CI_AS = I1.hbs_individualid collate SQL_Latin1_General_CP1_CI_AS
please check for null for column values applied in join, if still not working then you can try
where fieldname COLLATE DATABASE_DEFAULT = secondfieldname COLLATE DATABASE_DEFAULT

Related

Cannot resolve the collation conflict in Update query

I got several answers for this error but nothing works in my case.I have a simple update query
update students set studentID ='001093' where studentID ='1578093'
when i am trying to update in my sql db getting this collation error:
Cannot resolve the collation conflict between
"SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AI" in the equal
to operation.
what i tried
update students set studentID COLLATE SQL_Latin1_General_CP1_CI_AS ='001093' where studentID ='1578093' COLLATE SQL_Latin1_General_CP1_CI_AS
please help on this problem..i know we have enough duplicates but none of the solution is working for me
The collation should be applied to the string value, not the column:
update students
set studentID = '001093' COLLATE Latin1_General_CI_AI
where studentID = '1578093' COLLATE Latin1_General_CI_AI;
Good day, beginer_programer.
Try to apply the COLLATE DATABASE_DEFAULT:
Update students
SET studentID ='001093' collate database default
WHERE studentID = studentID ='1578093' collate database default

"SQL_Latin1_General_CP1_CI_AS" in the equal to operation

Hi i am new to SQL queries
My query is
ALTER TABLE ValidIBAN NOCHECK CONSTRAINT FK_ValidIBAN_Countries
UPDATE t
SET t.CountryID = s.Corrected
from #TempNewCountryID s,Countries t
where
s.Existing = t.CountryID
but after running this query i am getting
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AI" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Error Please suggest.
Depends on which logic is required (Accent sensitive or insensitive), use COLLATE on both sides of your equal sign: WHERE s.Existing COLLATE SQL_Latin1_General_CP1_CI_AI = t.CountryID COLLATE SQL_Latin1_General_CP1_CI_AI
If you update collate on table, or database(if needed), even in the server(if needed), then you never such an error.
ALTER TABLE tbl1 CONVERT TO CHARACTER SET utf8mb4 COLLATE SQL_Latin1_General_CP1_CI_AI;
I think it is better to update collate on the table rather than using it on queries.

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operations

This is my sql query
DELETE FROM [Prospects].[dbo].[P1]
WHERE RTRIM(LTRIM(DomainName)) IN
(SELECT RIGHT(UserEmail, LEN(UserEmail) - CHARINDEX('#', UserEmail)) UserEmail
FROM [Recruiter].[dbo].[tblSystemUser])
How to resolve this?
You can add
COLLATE DATABASE_DEFAULT
to the end of your query to convert it and fix the error, however this will take a performance hit.
As jarlh has suggested, changing the collation of the databases to be the same is the actual fix.
Try adding COLLATE DATABASE_DEFAULT to your query :
DELETE FROM [Prospects].[dbo].[P1]
WHERE RTRIM(LTRIM(DomainName)) COLLATE DATABASE_DEFAULT IN
(SELECT RIGHT(UserEmail, LEN(UserEmail) - CHARINDEX('#', UserEmail)) COLLATE DATABASE_DEFAULT UserEmail
FROM [Recruiter].[dbo].[tblSystemUser])
Try it's
DELETE FROM [Prospects].[dbo].[P1]
WHERE RTRIM(LTRIM(DomainName)) COLLATE DATABASE_DEFAULT IN
(SELECT RIGHT(UserEmail, LEN(UserEmail) - CHARINDEX('#', UserEmail)) UserEmail
FROM [Recruiter].[dbo].[tblSystemUser
])

SQL Collation mismatching issue

Have some collation(?) troubles when getting data from ADODB.RecordSet.
When selecting with SQL Management studio everything looks fine like
PriceMonitoring Справочник конкурентов2_Temp Table 6142061 dbo
Buuut, when i get data from powerdesigner's vbscript i got table names mismatching like
Table
Not in Model dbo.Ni?aai?iee eiieo?aioia2_Temp
Not in DB dbo.Справочник конкурентов2_Temp
For this moment i've already tried to specify different collations (COLLATE SQL_Latin1_General_CP1_CI_AS, Cyrillic_General_CI_AS, Ukrainian_CI_AS) in my sql script. I even changed DB collation, that doesn't help and had no effect to result. Any ideas, community?
That is a part of sql script.
SET NOCOUNT ON
USE DB_Control
SELECT ds.*, isnull(upo.Object_Name,'') as Object_Name_Updated, isnull(tuo.Object_Name,'') as Object_Name_Uncontrol
FROM
--
dbo.Design_Checksum AS ds
--
LEFT JOIN dbo.Uncontrolled_Object AS uo
ON uo.DB_Name = ds.DB_Name
AND uo.Object_Type_ID = ds.Object_Type_ID
AND uo.Schema_Name = ds.Schema_Name
AND uo.Object_Name COLLATE SQL_Latin1_General_CP1_CI_AS = ds.Object_Name COLLATE SQL_Latin1_General_CP1_CI_AS
--
LEFT JOIN dbo.Updated_Object AS upo
ON upo.DB_Name = ds.DB_Name
AND upo.Object_Type_ID = ds.Object_Type_ID
AND upo.Schema_Name = ds.Schema_Name
AND upo.Object_Name COLLATE SQL_Latin1_General_CP1_CI_AS = ds.Object_Name COLLATE SQL_Latin1_General_CP1_CI_AS
--
LEFT JOIN PD.Test_Uncontrolled_Object AS tuo
ON tuo.DB_Name = ds.DB_Name
AND tuo.Object_Type_ID = ds.Object_Type_ID
AND tuo.Schema_Name = ds.Schema_Name
AND tuo.Object_Name COLLATE SQL_Latin1_General_CP1_CI_AS = ds.Object_Name COLLATE SQL_Latin1_General_CP1_CI_AS
AND (tuo.Date_End IS NULL
OR tuo.Date_End > GETDATE())
WHERE
ds.DB_Name = 'PriceMonitoring'
AND uo.Object_Name IS NULL
ORDER BY
UPPER(REPLACE(ds.Object_Type_ID, '_', '!')),
UPPER(REPLACE(ds.Schema_Name, '_', '!')),
UPPER(REPLACE(ds.Object_Name, '_', '!'))

SQL Server Collation conflict - creating a view

i am trying to create a View in a Database A, that is filled by a select from the Database B and i am having a collation conflict, to be more exactly , its between ( Latin1_General_CI_AS" and "Latin1_General_BIN ). WHere(in the code) i need to put the collate?
Best Regards.
The code is here:
CREATE VIEW [dbo].[CML_SDG_MENSAL_ESTOQUE]
AS
select
SUM(dw_fato_faturmes.val_fatur) val_fatur,
SUM(dw_fato_faturmes.val_receita) val_receita,
SUM(dw_fato_faturmes.qtd_bonif_item) qtd_bonif_item,
SUM(dw_fato_faturmes.val_bonif_fatur) val_bonif_fatur,
SUM(dw_fato_faturmes.val_bonif_receita) val_bonif_receita,
SUM(dw_fato_faturmes.val_devol_fatur) val_devol_fatur,
SUM(dw_fato_faturmes.val_devol_receita) val_devol_receita,
DW_DIM_PRODUTO.B1_CODDB B1_CODDB,
dw_fato_faturmes.cod_produto cod_produto,
SUM(dw_fato_faturmes.qtd_estoque) qtd_estoque,
SUM(dw_fato_faturmes.qtd_devol) qtd_devol,
SUM(dw_fato_faturmes.qtd_item) qtd_item,
SUM(dw_fato_faturmes.qtd_meta) qtd_meta,
SUM(dw_fato_faturmes.qtd_pedido) qtd_pedido,
SUM(dw_fato_faturmes.qtd_item)+
SUM(dw_fato_faturmes.qtd_bonif_item)+
SUM(dw_fato_faturmes.qtd_devol) venda_liquida
(SUM(dw_fato_faturmes.qtd_item)
+SUM(dw_fato_faturmes.qtd_bonif_item)
+SUM(dw_fato_faturmes.qtd_devol))
+SUM(dw_fato_faturmes.qtd_pedido) venda___pedido
FROM
logixbi.dbo.dw_fato_faturmes dw_fato_faturmes,
logixbi.dbo.DW_DIM_CLIENTE DW_DIM_CLIENTE,
DW_DIM_EMPRESA DW_DIM_EMPRESA,
logixbi.dbo.DW_DIM_MARCA DW_DIM_MARCA,
logixbi.dbo.DW_DIM_PRODUTO DW_DIM_PRODUTO,
logixbi.dbo.DW_DIM_REPRESENTANTE DW_DIM_REPRESENTANTE
where
DW_DIM_EMPRESA.SM0_FILIAL=dw_fato_faturmes.filial and
DW_DIM_MARCA.BM_GRUPO=dw_fato_faturmes.grupo and
DW_DIM_PRODUTO.B1_COD=dw_fato_faturmes.cod_produto and
DW_DIM_REPRESENTANTE.A3_COD=dw_fato_faturmes.vendedor and
DW_DIM_CLIENTE.A1_COD=dw_fato_faturmes.cliente and
DW_DIM_CLIENTE.A1_LOJA=dw_fato_faturmes.loja
group by DW_DIM_PRODUTO.B1_CODDB,dw_fato_faturmes.cod_produto
In order to find wich column has wich collation use this snippet:
SELECT name, collation_name
FROM sys.columns
WHERE OBJECT_ID IN (SELECT OBJECT_ID
FROM sys.objects
WHERE type = 'U'
AND name = 'your_table_name'
)
AND name = 'your_column_name'
Once you find the columns try this:
column_1 COLLATE your_collation = column_2 COLLATE your_collation
It is better to stick to a single collation globally. Otherwise you will have problems. Here is a snippet that will give you all the columns on your database with a COLLATION different than the one in the database
SELECT [TABLE_NAME] = OBJECT_NAME([id]),
[COLUMN_NAME] = [name],
[COLLATION_NAME] = collation
FROM syscolumns
WHERE collation <> 'your_database_collation_type'
AND collation IS NOT NULL
AND OBJECTPROPERTY([id], N'IsUserTable')=1
Where to put it depends on where the conflict is.
I'd suggest on the joins
ie
DW_DIM_EMPRESA.SM0_FILIAL COLLATE Latin1_General_CI_AS =dw_fato_faturmes.filial COLLATE Latin1_General_CI_AS
This is happening due to operation between different collation types so try this for statement for comparison.
ColumnA = ColumnB collate database_default
Try to use this in all your character matching conditions in where clause:
colnameA COLLATE Latin1_General_CI_AS = columnnameB COLLATE Latin1_General_CI_AS