배경 : 프로덕션 환경에서 'E'테이블을 추가하지 않으면 정상적으로 작동합니다. 나는 아래의 쿼리를 실행하려고하지만 오류가 무엇입니까숫자에 대한 Varchar의 오류
:
Msg 8114, Level 16, State 5, Line 10
Error converting data type varchar to numeric.
이상한 것은 그것이 우리의 테스트 DB에 잘 실행하는입니다 - 숫자 때문에 조금 당황로 변환하려고 아무것도 표시되지 . 데이터 유형이 테스트 DB와 프로덕션 DB에서 동일하다고 가정 할 때 그 차이를 유발할 수있는 것은 무엇인지 모릅니다.
감사합니다.
/* - adding po balance qty causes duplicates
- adding stock category causes duplicates
- added PO comments using MAX function to return only first comment - gets rid of duplicates*/
/* Using NEW employee table as of 11/2 */
SELECT
S.team_member_name AS [ASSIGNED EMPLOYEE], --Using new employee table - only on bus unit as of 11/2
H.po_type AS [ PO TYPE],
G.order_no AS [GPS PO #],
P.po_number AS [SAP PO NUMBER],
M.department AS [DEPARTMENT],
G.order_qty AS [GPS QTY],
SUM(P.po_ordered_quantity) AS [SAP QUANTITY],
(SUM(P.po_ordered_quantity) - G.order_qty) AS [DIFFERENCE],
G.last_conf_date_cst AS [LAST CONFIRMED DATE],
K.business_unit_desc AS [BU],
M.[description] AS [DESCRIPTION],
P.material AS [MATERIAL],
MAX(P.comment) AS [PO COMMENT],
MIN(E.date) AS [FIRST SHOWN ON RPT]
FROM
(SELECT
order_no, order_qty, order_status,
last_conf_date_cst
FROM
asagdwpdx_prod.dbo.SimoxOrder1
UNION ALL
SELECT
order_no, order_qty, order_status,
last_conf_date_cst
FROM
asagdwpdx_prod.dbo.SimoxOrder2
UNION ALL
SELECT
order_no, order_qty, order_status,
last_conf_date_cst
FROM
asagdwpdx_prod.dbo.SimoxOrder3) G
JOIN
pdx_sap_user.dbo.vw_po_header H ON G.order_no = h.ahag_number
JOIN
pdx_sap_user.dbo.vw_po_item P ON H.po_number = P.po_number
JOIN
pdx_sap_user.dbo.vw_mm_material M ON P.material = M.material
JOIN
adi_user_maintained.dbo.SCM_PO_Employee_Name S ON P.po_number = S.po_number
JOIN
pdx_sap_user.dbo.vw_kd_business_unit K ON M.business_unit_code = K.business_unit_code
JOIN
adi_user_maintained.dbo.scm_po_error_tracking E ON E.po_number = P.po_number
WHERE
M.business_segment_code NOT IN ('421', '420', '422', '424') --exclude adi golf
AND E.report_source = 'gpsvssap_qty'
GROUP BY
G.order_no, -- GROUP BY needed on aggregate function in SELECT
G.order_qty,
G.order_status,
P.po_number,
P.material,
P.del_indicator,
H.po_created_by,
M.[description],
M.department,
S.team_member_name,
K.business_unit_desc,
G.last_conf_date_cst,
H.po_type
HAVING
G.order_qty <> SUM(P.po_ordered_quantity)
AND G.order_status NOT IN ('60', '90') -- excluding GPS cancelled (90) & shipped (60) - do we need to exclude other status'?
AND P.del_indicator <> 'L'
변환은 유니온 사이의 데이터 유형이 일치하지 않거나 조인 조건에 있기 때문에 발생합니다. 값을 암시 적으로 변환 할 수 없기 때문에 오류가 발생합니다. 이 값은 테스트 데이터베이스에없는 것 같습니다. 테스트 데이터베이스에서도 변환이 발생하지만 항상 성공적입니다. – HoneyBadger
이것이 맞습니다 - 필드 PO 번호는 두 테이블에서 다릅니다! 감사! – user3496218