Возникла проблема с этим объединением в базах данных. Когда я запускаю каждую секцию отдельно (до / после UNION), они работают очень хорошо. Тем не менее, после создания Союза я получаю ошибки.
Невозможно разрешить конфликт сопоставления между "Latin1_General_BIN" и "SQL_Latin1_General_CP1_CI_AS" в операции UNION. >
Когда я снова и снова пытаюсь решить эту проблему, добавив COLLATE в определенные области (столбцы из таблицы InspectionSpecification) оператора Select, я получаю отдельную ошибку.
Ошибка преобразования типа данных varchar в числовой. >
Я пытался преодолеть это, ЗАПРЕЩАЯ поля к INTs безрезультатно ... Любая помощь будет оценена.
Select WJAL.Job
,StockCode
,StockDescription
,Complete
,WJAL.Operation
,IExpUnitRunTim
,ParentQtyPlanEnt
,OperCompleted
,QtyCompleted
,QtyScrapped
,WorkCentre
,JobStartDate
,ActualFinishDate
,LEFT(RIGHT(StockDescription, CASE WHEN
LEN(StockDescription) - CHARINDEX(',',
StockDescription) - 1 < 0 THEN 0 ELSE LEN(StockDescription) - CHARINDEX(',',
StockDescription) - 1 END), CHARINDEX(' ', RIGHT(StockDescription, CASE WHEN
LEN(StockDescription) - CHARINDEX(',', StockDescription) - 1 < 0 THEN 1 ELSE
LEN(StockDescription) - CHARINDEX(',', StockDescription) - 1 END))) as
'Knife Model'
,PrevFinishDate
,PrevOperation
,PrevWorkCentre
,InspectionSpecification_No
,InspectionSpecification_type
,Status
,CASE WHEN LAG(WJAL.OperCompleted) OVER (PARTITION BY WJAL.Job Order By
WJAL.Operation) IS NULL THEN 'Y' ELSE LAG(WJAL.OperCompleted) OVER
(PARTITION BY WJAL.Job Order By WJAL.Operation) END as PrevCompleted
From (Select Job
,Operation
,IExpUnitRunTim
,ParentQtyPlanEnt
,OperCompleted
,QtyCompleted
,QtyScrapped
,WorkCentre
,ActualFinishDate
,LAG(ActualFinishDate) OVER (PARTITION BY Job Order By
Operation) as PrevFinishDate
,LAG(Operation) OVER (PARTITION BY Job Order By Operation) as
PrevOperation
,LAG(WorkCentre) OVER (PARTITION BY Job Order By Operation) as
PrevWorkCentre
From CompanyH.dbo.WipJobAllLab) WJAL
Join CompanyH.dbo.WipMaster t2
On WJAL.Job = t2.Job
Join [uniPoint_CompanyH].[dbo].[PT_InspectionSpecification] t3
On Case
WHEN t2.Warehouse = 'RD' and StockCode = t3.Part COLLATE
Latin1_General_BIN and t3.InspectionSpecification_type = 'First
Article' THEN 1
WHEN t2.Warehouse <> 'RD' and StockCode = t3.Part COLLATE
Latin1_General_BIN and t3.InspectionSpecification_type = 'In
Process' THEN 1
ELSE 0
END = 1
WHERE WorkCentre = 'INSPCT' and OperCompleted = 'N' and Complete = 'N' and
t3.Status <> 'Obsolete'
UNION
Select WJAL2.Job
,StockCode
,StockDescription
,Complete
,WJAL2.Operation
,IExpUnitRunTim
,ParentQtyPlanEnt
,OperCompleted
,QtyCompleted
,QtyScrapped
,WorkCentre
,JobStartDate
,ActualFinishDate
,LEFT(RIGHT(StockDescription, CASE WHEN
LEN(StockDescription) - CHARINDEX(',',
StockDescription) - 1 < 0 THEN 0 ELSE LEN(StockDescription) - CHARINDEX(',',
StockDescription) - 1 END), CHARINDEX(' ', RIGHT(StockDescription, CASE WHEN
LEN(StockDescription) - CHARINDEX(',', StockDescription) - 1 < 0 THEN 1 ELSE
LEN(StockDescription) - CHARINDEX(',', StockDescription) - 1 END))) as
'Knife Model'
,CASE WHEN LAG(OperCompleted) OVER (PARTITION BY WJAL2.Job Order By
WJAL2.Operation) IS NULL THEN 'Y' ELSE LAG(OperCompleted) OVER (PARTITION BY
WJAL2.Job Order By WJAL2.Operation) END as PrevCompleted
,PrevFinishDate
,PrevOperation
,PrevWorkCentre
,InspectionSpecification_No
,InspectionSpecification_type
,Status
From (Select Job
,Operation
,IExpUnitRunTim
,ParentQtyPlanEnt
,OperCompleted
,QtyCompleted
,QtyScrapped
,WorkCentre
,ActualFinishDate
,LAG(ActualFinishDate) OVER (PARTITION BY Job Order By Operation) as
PrevFinishDate
,LAG(Operation) OVER (PARTITION BY Job Order By Operation) as
PrevOperation
,LAG(WorkCentre) OVER (PARTITION BY Job Order By Operation) as
PrevWorkCentre
From CompanyH.dbo.WipJobAllLab) WJAL2
Join CompanyH.dbo.WipMaster t5
On WJAL2.Job = t5.Job
LEFT Join [uniPoint_CompanyH].[dbo].[PT_InspectionSpecification] t6
On t5.StockCode = t6.Part COLLATE Latin1_General_BIN
WHERE WorkCentre = 'INSPCT' and OperCompleted = 'N' and Complete = 'N' and
t6.InspectionSpecification_No is NULL