Teradata SQL Update Table "Query Error 3802 Database 'oo' does not exist" - sql

I need help with the following query code. Currently it is giving me the 3802 query error "Database does not exist". Well I did my "from" selection query as 'oo', so that definitely exists. This worked yesterday with some minor changes to the "from" part of the query. The assistance is appreciated.
UPDATE snd_bqa.open_order_all_test
FROM (
SELECT
CASE WHEN m.order_status_desc = 'Completed' AND NVL(c.supptype, 'NULL') <> 'CAN'
THEN 'YES'
ELSE 'NO'
END AS "Order Complete",
CASE WHEN m.order_status_desc = 'Completed' AND c.supptype = 'CAN'
THEN 'YES'
ELSE 'NO'
END AS "Order Cancelled",
CASE WHEN pih.effective_start_date IS NOT NULL AND pih.product_instance_status_code = 3
THEN 'YES'
ELSE 'NO'
END AS "Service Active in PB",
c.ordernumber,
c1.order_requested_due_date,
c.creationdate AS "Order Creation Date",
c.ordersubmitdate AS "Order Submit Date",
c.lastupdateddate,
c.supptype,
m.order_status_desc,
m.phase_stage,
cus.sub_nasp_id,
cus.gch_id,
b.work_order_no,
b.itemcode,
b.instance_id,
COALESCE(b.specific_date, b.standard_date) AS "Service Req Due Date",
m.milestone,
m.milestone_desc,
cus.custlegalname,
a.account_number,
vle.vle_id,
vle.currency_cd,
cus.duns_number,
a.cle_vle_id,
CURRENT_TIMESTAMP(2) AS "Originally Loaded",
CURRENT_TIMESTAMP(2) AS "Last Upd",
CAST((CASE WHEN m.order_status_desc = 'Completed' AND NVL(c.supptype, 'NULL') <> 'CAN'
THEN c.lastupdateddate
ELSE NULL
END) AS TIMESTAMP(2)) "Order Completed Date",
CAST((CASE WHEN m.order_status_desc = 'Completed' AND c.supptype = 'CAN'
THEN c.lastupdateddate
ELSE NULL
end) AS TIMESTAMP(2)) "Order Cancelled Date",
pih.last_modified AS "Service Last Modified Date",
pih.effective_start_date AS "Service Effective Date"
FROM (
SELECT *
FROM edw_stg_ord_cw_vw.cwpc_basketitem
WHERE itemcode LIKE 'PR%'
AND (instance_id, lastupdateddate) IN (
SELECT instance_id, MAX(lastupdateddate)
FROM edw_stg_ord_cw_vw.cwpc_basketitem
GROUP BY instance_id
)) AS b
INNER JOIN edw_stg_ord_cw_vw.cworderinstance AS c
ON c.basket_id = b.basketid
AND c.isactive = 1
AND c.request_type = 'ORD'
LEFT JOIN (
SELECT c.ordernumber,
MAX(COALESCE(b.specific_date, b.standard_date)) order_requested_due_date
FROM edw_stg_ord_cw_vw.cworderinstance AS c
INNER JOIN edw_stg_ord_cw_vw.cwpc_basketitem AS b
ON b.basketid = c.basket_id
AND c.request_type = 'ORD'
AND c.isactive = 1
GROUP BY c.ordernumber
) AS c1
ON c1.ordernumber = c.ordernumber
LEFT JOIN edw_stg_ord_cw_vw.uno_customer AS cus
ON cus.cworderid = c.cwdocid
AND cus.oi_customer_id = c.ordering_customer_id
LEFT JOIN edw_stg_ord_cw_vw.uno_milestone AS m
ON m.milestone_id = c.milestone_id
LEFT JOIN edw_stg_ord_cw_vw.uno_account AS a
ON a.cworderid = c.cwdocid
AND b.account_id = a.oi_account_id
LEFT JOIN edw_stg_ord_cw_vw.uno_cle_vle AS vle
ON vle.cle_vle_id = a.cle_vle_id
AND c.cwdocid = vle.cworderid
INNER JOIN snd_bqa.open_order_all_test tst
ON tst."Service Instance ID" = b.instance_id
AND tst."Milestone" <> m.milestone
LEFT JOIN edw_pb_stg_vw.product_instance_history AS pih
ON pih.general_5 = tst."Service Instance ID"
WHERE cus.sub_nasp_id NOT IN ('19HNYO', '23MAXA', '19HNYR', '10INTD')
AND COALESCE(b.specific_date, b.standard_date, c1.order_requested_due_date) BETWEEN CURRENT_DATE - 60 AND CURRENT_DATE - 30
) oo
SET "Order Complete" = oo."Order Complete",
"Order Cancelled" = oo."Order Cancelled",
"Service Active in PB" = oo."Service Active in PB",
"Service Order Number" = oo.ordernumber,
"Order Requested Due Date" = oo.order_requested_due_date,
"Order Last Updated" = oo.lastupdateddate,
"Order Creation Date" = oo."Order Creation Date",
"Order Submit Date" = oo."Order Submit Date",
"Order Supp Type" = oo.c.supptype,
"Order Status" = oo.order_status_desc,
"Phase Stage" = oo.phase_stage,
"Milestone" = oo.milestone,
"Milestone Description" = oo.milestone_desc,
"NASP ID" = oo.sub_nasp_id,
"GCH ID" = oo.gch_id,
"Work Order Numbers" = oo.work_order_no,
"Product Code" = oo.itemcode,
"Service Requested Due Date" = oo."Service Req Due Date",
"Customer Name" = oo.custlegalname,
"Account Number" = oo.account_number,
"VLE ID" = oo.vle_id,
"Currency Code" = oo.currency_cd,
"DUNs Number" = oo.duns_number,
"CLE VLE ID" = oo.cle_vle_id,
"Last Record Update" = oo."Last Upd",
"Order Completed Date" = oo."Order Completed Date",
"Order Cancelled Date" = oo."Order Cancelled Date",
"Service Last Modified Date" = oo."Service Last Modified Date",
"Service Effective Date" = oo."Service Effective Date"
WHERE open_order_all_test."Service Instance ID" = oo.instance_id
;

I found the issue. I had oo.c.supptype, when it should have just been oo.supptype
This caused Teradata to think 'oo' was referring to a database. case closed.

Related

How to create a list that shows all unique workers that had service on a week

I am trying to create a query that shows the list of the workers that have at least a shift during the week, but in the query that I created the names of the workers appear multiple times according to the number of shifts they have completed during the period.
WITH time_frame AS
(SELECT date_trunc('week',NOW())-interval '1 week')
select
null as "Employer Ref",
ff.id as "Personnel Ref",
null as "Employment Sequence No",
ff.first_name as Forename,
ff.last_name as Surname,
null as "Second forename",
null as "Third forename ",
case ff.gender
when 'F' then 'Miss'
when 'M' then 'Mr'
else null
end as Title,
null as "Known as",
ff.address1 as "Address line 1",
ff.address2 as "Address line 2",
ff.city as "Address line 3",
null as "Address line 4",
null as "Address line 5",
lp.postcode as Postcode,
'UK' as Country,
null as "Telephone number",
ff.gender as gender,
ff.birth_date as "Date of birth",
ff.mobile as "Mobile Telephone",
au.email as "Email Address",
ff.sort_code as "Bank1 sort code",
ff.account_number as "Bank1 account number",
concat(ff.first_name,' ',ff.last_name) as "Bank1 account name"
from booking_booking bb
join freelancer_freelancer ff on bb.freelancer_id = ff.id
join job_jobrequest jj on bb.jobrequest_id = jj.id
join auth_user au on au.id = ff.user_id
join location_postcode lp on lp.id = jj.postcode_id
WHERE bb.status != 'FC'
AND bb.status != 'BC'
AND bb.status != 'BU'
AND jj.agency_id IN('1')
AND date_trunc('week',jj.date) =
(SELECT *
FROM time_frame)

How do you use sql count to find the number of position control numbers for each person in this query?

I am trying to count the number of position control numbers for each employee. I tried using SELECT COUNT(hrp.pos_ctl_no), but its only returning the count for each position control number and not the count of the position control numbers for each person. In the example result provided , Abbott Edith has 2 position control numbers. I only want her to appear once in the spreadsheet with a count of 2 by her name to indicate that she has 2 position control numbers. Instead it is showing her twice because of the 2 different control numbers.
Here is my sql query:
SELECT COUNT(hrp.pos_ctl_no),
empm.empl_no as "Employee Number",
hr.last_name as "Last Name",
hr.first_name as "First Name",
isnull(hr.mid_name, '') as "Middle Name",
cctr.cctr_desc as "Work Location",
sj_desc as "Job Title",
code.st_job_cd as "Job Code",
hrp.pos_ctl_no as "Position Control Number"
FROM cenoff.hrperson hr
JOIN cenoff.prempm empm on empm.pers_id = hr.pers_id
JOIN [NGSQLSVR].[CENOFF].[PREMPJOB] job on job.empl_no = empm.empl_no
JOIN [NGSQLSVR].[CENOFF].[CCTR] cctr on cctr.glcval_val = job.glcval_val
JOIN [NGSQLSVR].[CENOFF].[PREMPCPI] CPI on cpi.empl_no = empm.empl_no
JOIN [NGSQLSVR].[CENOFF].[hrstpcode] code on code.st_job_cd = cpi.st_job_cd
JOIN [NGSQLSVR].[CENOFF].[pretype] on pretype.empl_type = job.empl_type
LEFT JOIN [NGSQLSVR].[CENOFF].[hrpcej] hrp on hrp.pers_id = hr.pers_id
WHERE
job.job_type = 'P'
and cpi.assign_perc = '1.0000'
and job.job_no = '1'
--and hrp.pos_ctl_no is NULL
and empm.cpi_stat = 'A'
--and cctr.cctr_desc = 'Isabella Complex'
GROUP BY
empm.empl_no,
hrp.pos_ctl_no,
hr.last_name,
hr.first_name,
isnull(hr.mid_name, ''),
cctr.cctr_desc,
sj_desc,
code.st_job_cd,
pretype.empl_type_desc,
cpi.assign_perc,
job.job_no,
hr.hr_stat_cd,
empm.cpi_stat,
empm.hr_stat_cd,
job.hr_stat_cd,
pos_began,
hrp.pos_ended,
job.hire_date,
enroll_end_date,
contr_end_date
ORDER BY hr.last_name, hr.first_name
Results
Without the data it's very difficult to understand. Removing pos_ctl_no from group by clause might do the trick.
SELECT COUNT(hrp.pos_ctl_no),
empm.empl_no as "Employee Number",
hr.last_name as "Last Name",
hr.first_name as "First Name",
isnull(hr.mid_name, '') as "Middle Name",
cctr.cctr_desc as "Work Location",
sj_desc as "Job Title",
code.st_job_cd as "Job Code",
FROM cenoff.hrperson hr
JOIN cenoff.prempm empm on empm.pers_id = hr.pers_id
JOIN [NGSQLSVR].[CENOFF].[PREMPJOB] job on job.empl_no = empm.empl_no
JOIN [NGSQLSVR].[CENOFF].[CCTR] cctr on cctr.glcval_val = job.glcval_val
JOIN [NGSQLSVR].[CENOFF].[PREMPCPI] CPI on cpi.empl_no = empm.empl_no
JOIN [NGSQLSVR].[CENOFF].[hrstpcode] code on code.st_job_cd = cpi.st_job_cd
JOIN [NGSQLSVR].[CENOFF].[pretype] on pretype.empl_type = job.empl_type
LEFT JOIN [NGSQLSVR].[CENOFF].[hrpcej] hrp on hrp.pers_id = hr.pers_id
WHERE
job.job_type = 'P'
and cpi.assign_perc = '1.0000'
and job.job_no = '1'
--and hrp.pos_ctl_no is NULL
and empm.cpi_stat = 'A'
--and cctr.cctr_desc = 'Isabella Complex'
GROUP BY
empm.empl_no,
hr.last_name,
hr.first_name,
isnull(hr.mid_name, ''),
cctr.cctr_desc,
sj_desc,
code.st_job_cd,
ORDER BY hr.last_name, hr.first_name

ORA-01427 error in crystal report

Looking for a resolution to the error
ORA-01427 single-row subquery returns more than one row
I am getting on this SQL code. This is a command in my crystal report which I have narrowed the error down to. But there are multiple sub-queries in this code and I can't find the best approach to getting this error to resolve. I know that this type of error is generally associated with using '=' in a select statement for a sub-query and that I should use another such as IN, LIKE, etc. Any advice would be helpful.
Thanks,
SELECT
JREQ.HRORGANIZATION,
JREQ.JOBREQUISITION AS "Req #",
cmdPoolRef."Pool Req Ref" AS "Candidate Pool",
cmdDualPostingRef."Dual Posting Ref" AS "Dual Posting Ref",
DEPTNAME.DESCRIPTION AS "Department Name",
JOB.DESCRIPTION AS "Job Title",
JREQ.OPENDATE AS "Date Opened",
CASE JREQ.STATUS
WHEN 1 THEN 'Pending'
WHEN 2 THEN 'Open'
WHEN 3 THEN 'On Hold'
WHEN 4 THEN 'Cancelled'
WHEN 5 THEN 'Filled'
WHEN 7 THEN 'Draft'
WHEN 8 THEN 'Approval Requested'
ELSE CONCAT('Unknown',JREQ.STATUS)
END AS "Req Status",
cmdFTELimited."FTE Limted" AS "FTE",
JREQ.INITIALOPENINGS AS "# of Positions",
JREQ.FILLEDOPENINGS AS "# of Positions Filled",
DEPTNAME.SHORTDESCRIPTION AS "Cost Center",
JREQ.REASONFOROPENING AS "Req Reason Code",
cmdEmpReplacing."Replacement ID" AS "Replacement ID",
cmdEmpReplacing."Replacement Name" AS "Replacement Name",
JREQ."UNION" AS "Union",
DEPT_LOCATION.DESCRIPTION AS "Location",
JREQ.SALARYSTRUCTURE AS "Family",
POS.SALARYSTRUCTUREGRADE AS "Grade",
TRIM(RECRUITER.PRESENTATIONNAMESNAPSHOT) AS "Recruiter Name",
TRIM(HIREMGR.PRESENTATIONNAMESNAPSHOT) AS "Hiring Manager",
cmdApptType."Appt Type" AS "Appointment Type",
JREQ.CATEGORY AS "Category",
cmdCandidateHired."Person Hired" AS "Person Hired",
cmdCandidateHired."Start Date" AS "Start Date",
cmdCandidateHired."Offer Amount" AS "Offer Amount",
VW.ENTITYORGUNIT
FROM LTMPROD.JOBREQUISITION JREQ
LEFT OUTER JOIN LTMPROD.HRORGANIZATIONUNIT DEPTNAME ON JREQ.HRORGANIZATIONUNIT = DEPTNAME.HRORGANIZATIONUNIT
LEFT OUTER JOIN LTMPROD.HRLOCATION DEPT_LOCATION ON JREQ.LOCATION = DEPT_LOCATION.HRLOCATION
LEFT OUTER JOIN LTMPROD.EMPLOYEE RECRUITER ON JREQ.RECRUITER = RECRUITER.EMPLOYEE
LEFT OUTER JOIN LTMPROD.POSITION POS ON JREQ.POSITION = POS.POSITION
LEFT OUTER JOIN LTMPROD.EMPLOYEE HIREMGR ON JREQ.HIRINGMANAGER = HIREMGR.EMPLOYEE
LEFT OUTER JOIN LTMPROD.JOB ON POS.JOB = JOB.JOB
LEFT OUTER JOIN LTMPROD.XXX_ORGUNIT_ENTITY_VIEW VW ON JREQ.HRORGANIZATIONUNIT = VW.HRORGANIZATIONUNIT
LEFT OUTER JOIN (
SELECT TO_NUMBER(UFS.ALPHA) AS "ReplaceThisEmp",
UFS.UFSUNIQUEID,
REPLACETHISEMPLOYEE.EMPLOYEE AS "Replacement ID",
TRIM(REPLACETHISEMPLOYEE.PRESENTATIONNAMESNAPSHOT) AS "Replacement Name"
FROM LTMPROD.USERFIELD_STORAGE UFS
LEFT OUTER JOIN LTMPROD.EMPLOYEE REPLACETHISEMPLOYEE ON TO_NUMBER(UFS.ALPHA) = REPLACETHISEMPLOYEE.EMPLOYEE
WHERE UFS.UFSCLASSNAME = 'JobRequisition'
AND UFS.UFSFIELDNAME = 'EmployeeReplacingID'
) cmdEmpReplacing ON cmdEmpReplacing.UFSUNIQUEID = JREQ.UNIQUEID
LEFT OUTER JOIN (
SELECT JA.JOBREQUISITION,
JA.EMPLOYMENTSTARTDATE AS "Start Date",
JA.SALARY AS "Offer Amount",
TRIM(CAN.PRESENTATIONNAMESNAPSHOT) AS "Person Hired"
FROM LTMPROD.JOBAPPLICATION JA
LEFT OUTER JOIN LTMPROD.CANDIDATE CAN ON CAN.CANDIDATE = JA.CANDIDATE
WHERE JA.SELECTIONPROCESS = 9
) cmdCandidateHired ON cmdCandidateHired.JOBREQUISITION = JREQ.JOBREQUISITION
LEFT OUTER JOIN (
SELECT UFS.ALPHA AS "Appt Type", UFS.UFSUNIQUEID
FROM LTMPROD.USERFIELD_STORAGE UFS
WHERE UFS.UFSCLASSNAME = 'JobRequisition'
AND UFS.UFSFIELDNAME = 'AppointmentType'
) cmdApptType ON cmdApptType.UFSUNIQUEID = JREQ.UNIQUEID
LEFT OUTER JOIN (
SELECT UFS.ALPHA AS "Pool Req Ref", UFS.UFSUNIQUEID
FROM LTMPROD.USERFIELD_STORAGE UFS
WHERE UFS.UFSCLASSNAME = 'JobRequisition'
AND UFS.UFSFIELDNAME = 'PoolRequistionReference'
) cmdPoolRef ON cmdPoolRef.UFSUNIQUEID = JREQ.UNIQUEID
LEFT OUTER JOIN (
SELECT UFS.ALPHA AS "Dual Posting Ref", UFS.UFSUNIQUEID
FROM LTMPROD.USERFIELD_STORAGE UFS
WHERE UFS.UFSCLASSNAME = 'JobRequisition'
AND UFS.UFSFIELDNAME = 'DualPostingReference'
) cmdDualPostingRef ON cmdDualPostingRef.UFSUNIQUEID = JREQ.UNIQUEID
LEFT OUTER JOIN (
SELECT UF.ALPHA AS "FTE Limted",UF.UFSUNIQUEID
FROM LTMPROD.USERFIELD_STORAGE UF
WHERE UF.UFSCLASSNAME = 'JobRequisition'
AND UF.UFSFIELDNAME = 'FTELimited'
) cmdFTELimited ON cmdFTELimited.UFSUNIQUEID = JREQ.UNIQUEID
Note: Crystal Report could have generated this error not due to the above query but other queries you might be using within the report, say for dynamic parameters?
Check all other queries used in the report, and as you mentioned, it is somewhere where oracle expects one record and got more: usually an ( = (select...))

I am trying to write the query attached, but getting the error "multi-part identifier could not be bound"

Declare #Vaccine varchar(300)
Set #Vaccine = CASE
WHEN OHM.ohmuser.IMMTYPE.FLDCODE IN ('105','HBIG','HEPA') THEN 'HEPATITIS'
WHEN OHM.ohmuser.IMMTYPE.FLDCODE IN ('109','109A','109B','109C','HIN1IM','HIN1IS','FLUID','FLUHD','FLULOA','109QIM','109QIS') THEN 'FLU'
WHEN OHM.ohmuser.IMMTYPE.FLDCODE IN ('102','104','107','108','MMRDEC') THEN 'MMR'
--WHEN OHM.ohmuser.IMMTYPE.FLDCODE IN ('105','HBIG','HEPA') THEN 'MISC'
--WHEN OHM.ohmuser.IMMTYPE.FLDCODE IN ('105','HBIG','HEPA') THEN 'TDAP'
--WHEN OHM.ohmuser.IMMTYPE.FLDCODE IN ('105','HBIG','HEPA') THEN 'FIT'
--WHEN OHM.ohmuser.IMMTYPE.FLDCODE IN ('105','HBIG','HEPA') THEN 'SCREEN'
ELSE NULL
END
BEGIN
SELECT
tEmployee.ID as "Employee Number",
tEmployee.LastName,
tEmployee.FirstName,
tEmployee.BirthDate as "Date of Birth",
tEmployee.Sex as "Gender",
tEmployeeWorkDetail.Department
FROM OHM.ohmuser.tEmployee LEFT OUTER JOIN OHM.ohmuser.tEmployeeWorkDetail on tEmployee.EmployeeID = tEmployeeWorkDetail.EmployeeID
--WHERE tEmployeeWorkDetail.Department = '100801000'
SELECT CASE #Vaccine
WHEN 'HEPATITIS' THEN
(SELECT
HEPATITS.FLDDATE1 as "Hepatitis Vaccine Date",
HEPATITS.FLDDATE2 as "Hepatitis Vaccine Date2",
HEPATITS.FLDDATE3 as "Hepatitis Vaccine Date3",
IMMUNE.FLDTYPE as "Vaccine",
IMMTYPE.FLDDESCR as "Vaccine Descr",
HEPATITS.FLDADM1 as "Hepatitis Given By",
HEPATITS.FLDMAN1 as "Manufacturer",
HEPLAB.FLDCOMMENT as "Comments",
HEPATITS.FLDLOGNUM1 as "Lot #1",
HEPATITS.FLDLOTNUM2 as "Lot #2",
HEPATITS.FLDLOTNUM3 as "Lot #3",
HEPLAB.FLDDATE as "Lab Date",
HEPLAB.FLDSANTBVAL as "Surface Antibody"
FROM OHM.ohmuser.tEmployee LEFT OUTER JOIN OHM.ohmuser.HEPATITS ON tEmployee.EmployeeID = HEPATITS.FLDEMPLOYEE LEFT OUTER JOIN
OHM.ohmuser.HEPLAB ON tEmployee.EmployeeID = HEPLAB.FLDEMPLOYEE LEFT OUTER JOIN
OHM.ohmuser.IMMUNE ON tEmployee.EmployeeID = IMMUNE.FLDEMPLOYEE INNER JOIN
OHM.ohmuser.IMMTYPE ON IMMUNE.FLDTYPE = IMMTYPE.FLDCODE)
WHEN 'FLU' THEN
(SELECT
IMMUNE.FLDDATE as "Date",
IMMUNE.FLDTYPE as "Vaccine",
IMMTYPE.FLDDESCR as "Vaccine Descr",
IMMUNE.FLDNOTE1 as "Comments",
IMMUNE.FLDMANUFACT as "Mfr",
IMMUNE.FLDLOTNUM as "Lot #",
IMMUNE.FLDADMIN as "Given By"
FROM OHM.ohmuser.tEmployee LEFT OUTER JOIN
OHM.ohmuser.IMMUNE ON tEmployee.EmployeeID = IMMUNE.FLDEMPLOYEE INNER JOIN
OHM.ohmuser.IMMTYPE ON IMMUNE.FLDTYPE = IMMTYPE.FLDCODE)
WHEN 'MMR' THEN
(SELECT
IMMUNE.FLDDATE as "Date",
IMMUNE.FLDTYPE as "Procedure",
IMMTYPE.FLDDESCR as "Procedure Descr",
IMMUNE.FLDNOTE1 as "Comments",
IMMUNE.FLDMANUFACT as "Mfr",
IMMUNE.FLDLOTNUM as "Lot #",
IMMUNE.FLDADMIN as "Given By",
TITER.FLDDATE as "Titer Date",
TITER.FLDTYPE as "Titer Type",
TITER.FLDRESULT as "Titer Result",
TITER.FLDCLINIC as "Clinic",
TITER.FLDCOMMENT as "Comments"
FROM OHM.ohmuser.tEmployee LEFT OUTER JOIN OHM.ohmuser.TITER ON tEmployee.EmployeeID = TITER.FLDEMPLOYEE LEFT OUTER JOIN
OHM.ohmuser.IMMUNE ON tEmployee.EmployeeID = IMMUNE.FLDEMPLOYEE INNER JOIN
OHM.ohmuser.IMMTYPE ON IMMUNE.FLDTYPE = IMMTYPE.FLDCODE)
End
End
I want the first part of the SQL to print once. If #Vaccine is equal to ‘Hepatitis’ or ‘Flu’ or ‘MMR’ then it should print additional data. However, I am getting an error that says “The multi-part identifier "OHM.ohmuser.IMMTYPE.FLDCODE" could not be bound.” What am I doing wrong?
The message is basically saying OHM.ohmuser.IMMTYPE.FLDCODE doesn't exist either on any of the SERVER (OHM), DATABASE (ohmuser), SCHEMA (IMMTYPE), TABLE (FLDCODE). Have a quick check to ensure it does on all.
What I have noticed is that you have prefixed all your tables with "OHM.ohmuser". I'm assuming that this is a stored procedure and its in the same database "OHM.ohmuser". Hence, you should be able to remove all instances of it making your code more readable and less prone to error.

DB2 SQL Select Statement & Group By

I am having trouble getting my query to group correctly. I need to include the TELLERACTIVITY.ENTRY_DATE date column so I can filter by the date later on. However, I do not want it to group by the TELLERACTIVITY.ENTRY_DATE date because it gives me more results than I want.
SELECT DISTINCT ACTIVITYINFO.MEMBER_NBR AS "Member Number"
,ACCOUNT.ACCOUNT_NBR AS "Account Number"
,TELLERACTIVITY.FOCUS_TELLER_ID AS "Teller ID"
,TELLERACTIVITY.ENTRY_DATE AS "Date"
,SUM(( CASE WHEN OPERATOR.BRANCH_NBR = 1 THEN 1
ELSE 0
END )) AS "Branch 1"
,SUM(( CASE WHEN OPERATOR.BRANCH_NBR = 2 THEN 1
ELSE 0
END )) AS "Branch 2"
,SUM(( CASE WHEN OPERATOR.BRANCH_NBR = 3 THEN 1
ELSE 0
END )) AS "Branch 3"
,SUM(( CASE WHEN OPERATOR.BRANCH_NBR = 4 THEN 1
ELSE 0
END )) AS "Branch 4"
FROM TELLERACTIVITY
JOIN OPERATOR
ON TELLERACTIVITY.FOCUS_TELLER_ID = OPERATOR.OPR_NBR
JOIN ACTIVITY
ON TELLERACTIVITY.ACTIVITY_ID = ACTIVITY.ACTIVITY_ID
AND TELLERACTIVITY.FOCUS_TELLER_ID = ACTIVITY.FOCUS_TELLER_ID
AND TELLERACTIVITY.ENTRY_DATE = ACTIVITY.ENTRY_DATE
JOIN ACTIVITYINFO
ON ACTIVITY.ACTIVITY_ID = ACTIVITYINFO.ACTIVITY_ID
JOIN ACCOUNT
ON ACTIVITYINFO.MEMBER_NBR = ACCOUNT.MEMBER_NBR
AND ACTIVITYINFO.ACCOUNT_NBR = ACCOUNT.ACCOUNT_NBR
WHERE TELLERACTIVITY.FOCUS_TELLER_ID < 6000
GROUP BY ACTIVITYINFO.MEMBER_NBR
,ACCOUNT.ACCOUNT_NBR
,OPERATOR.BRANCH_NBR
,TELLERACTIVITY.FOCUS_TELLER_ID
,TELLERACTIVITY.ENTRY_DATE
ORDER BY ACTIVITYINFO.MEMBER_NBR