Estou tentando realizar uma consulta e está dando o seguinte erro:
Unknown column 'FILIAL' in 'field list'
A consulta é a seguinte:
SELECT TICKET, DATAHORA, TIPO, ESTADO, CRITICIDADE, LOGIN, PARECER, INFOPEND, PROP, DATAPROP, PREV, SRD, PROT, REAB,FILIAL
FROM (
SELECT
TC.TN TICKET, TC.CREATE_TIME DATAHORA, TT.NAME TIPO, TS.NAME ESTADO, TP.NAME CRITICIDADE, US.LOGIN LOGIN,
CASE
WHEN TH.NAME LIKE '%PARECER%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
ELSE ''
END PARECER,
CASE
WHEN TH.NAME LIKE '%INFORMACOESPENDENTES%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
ELSE ''
END INFOPEND,
CASE
WHEN AR.A_SUBJECT LIKE '%ATUALIZAÇÃO PROPRIETÁRIO%' THEN LEFT(AR.A_FROM, POSITION('<' IN (AR.A_FROM))-1)
ELSE ''
END PROP,
CASE
WHEN AR.A_SUBJECT LIKE '%ATUALIZAÇÃO PROPRIETÁRIO%' THEN (AR.CREATE_TIME)
ELSE ''
END DATAPROP,
CASE
WHEN TH.NAME LIKE '%PREVISAOATENDIMENTO%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
ELSE ''
END PREV,
CASE
WHEN TH.NAME LIKE '%SRD%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
ELSE ''
END SRD,
CASE
WHEN TH.NAME LIKE '%PROTOCOLO%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
ELSE ''
END PROT,
CASE
WHEN TS.NAME LIKE '%REABERTO' THEN (TS.NAME)
ELSE ''
END REAB
FROM OTRS2.TICKET TC
INNER JOIN OTRS2.TICKET_TYPE TT ON TC.TYPE_ID = TT.ID
INNER JOIN OTRS2.TICKET_STATE TS ON TC.TICKET_STATE_ID = TS.ID
INNER JOIN OTRS2.TICKET_PRIORITY TP ON TC.TICKET_PRIORITY_ID=TP.ID
INNER JOIN OTRS2.USERS US ON TC.CREATE_BY=US.ID
INNER JOIN OTRS2.TICKET_HISTORY TH ON TC.ID=TH.TICKET_ID
INNER JOIN OTRS2.ARTICLE AR ON TC.ID=AR.TICKET_ID
UNION
SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, CUSTOMER.LOGIN FILIAL FROM OTRS2.CUSTOMER_USER CUSTOMER
) A
PS: Até eu colocar o UNION
, a query estava funcionando direitinho e retornando os resultados.