ORA-00933: SQL command not properly ended ORA-06512: - sql

What is wrong with this ,
I get this error
OLE DB provider "OraOLEDB.Oracle" for linked server "hades" returned message "ORA-00933: SQL command not properly ended
ORA-06512: at "SAAP.EDI", line 1416".
OLE DB provider "OraOLEDB.Oracle" for linked server "hades" returned message "ORA-00933: SQL command not properly ended
ORA-06512: at "SAAP.EDI", line 1416".
Msg 7320, Level 16, State 2, Line 2
Cannot execute the query "select * from table(edi.ftCustomerCatalog('010','145','000164'))" against OLE DB provider "OraOLEDB.Oracle" for linked server "hades".
Code:
function ftCustomerCatalog(comno varchar2,cpls varchar2, cuno varchar2) return tblCustomerCatalog pipelined
is
c sys_refCursor;
r recCustomerCatalog;
sq varchar2(3000);
begin
sq:='select
a.comno
,a.t$cpls
,coalesce(a.t$cuno,b.t$cuno) as t$cuno
,a.t$cpgs,a.t$item
,a.t$Upcd
,a.t$dsca
,a.t$wght
,a.t$ship
,coalesce(b.t$stdt,c.t$stdt,d.t$stdt,e.t$stdt,f.t$stdt) as T$STDT
,coalesce(b.t$tdat,c.t$tdat,d.t$tdat,e.t$tdat,f.t$tdat) as t$tdat
,coalesce(b.t$qanp,c.t$qanp,d.t$qanp,e.t$qanp,f.t$qanp) as t$qanp
,a.t$pric
,coalesce(b.t$disc,c.t$disc,d.t$disc,e.t$disc,f.t$disc) as t$disc
,coalesce(b.source,c.source,d.source,e.source,f.source) as Source
from table(edi.ftAllPlCatalogs(:comno,cpls)) where t$cuno=:cuno a
left join table(edi.ft30ciDiscounts(:comno,:cpls,:cuno)) b on a.t$item=b.T$item and a.t$cuno=b.t$cuno
Left Join table(edi.ft31CPGDiscounts(:comno,:cpls,:cuno)) c on a.t$cpgs=c.t$cpgs
left Join table(edi.ft31Cdiscounts (:comno,:cpls,:cuno)) d on d.t$cpgs is null
left join table(edi.ft33plpgDiscounts(:comno,:cpls)) e on d.t$disc is null and a.t$cpgs=e.t$cpgs
left join table(edi.ft33PlDiscount(:comno,:cpls)) f on e.t$disc is null
Order by A.T$CPGS, a.t$item;';
Open c for SQ using
comno,cpls,cuno
,comno,cpls,cuno
,comno,cpls,cuno
,comno,cpls,cuno
,comno,cpls
,comno,cpls;
LOOP
fetch c into r;
exit when c%notfound;
pipe row(r);
END LOOP;
close c;
end;

I don't think the syntax
t$stdt=coalesce(b.t$stdt,c.t$stdt,d.t$stdt,e.t$stdt,f.t$stdt)
is valid in Oracle.
Assuming that the meaning is to provide an alias for the expression, I believe the Oracle equivalent would be:
coalesce(b.t$stdt,c.t$stdt,d.t$stdt,e.t$stdt,f.t$stdt) AS stdt
(the AS keyword begin optional)

Related

`FOR UPDATE` breaks batch execution in HANA

HANA 102.05 fails to execute the following code:
CREATE TABLE ATABLE( f INT );
CREATE PROCEDURE TestProc()
AS
BEGIN
SELECT f FROM ATABLE
FOR UPDATE; -- Without FOR UPDATE it works
END;
SELECT 'Hello' FROM DUMMY;
complaining that:
SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "SELECT": line 8 col 2 (at pos 124)
which points outside the proceudure, at SELECT 'Hello'. The procedure itself compiles without error. The entire script completes successfully if I remove the FOR UPDATE directive. What is wrong with the original?
Update
When I execute the same query from hdbsql.exe I get:
0 rows affected (overall time 26,076 msec; server time 6518 usec)
* 257: sql syntax error: line 5 col 9 (at pos 71) SQLSTATE: HY000
* 257: sql syntax error: incorrect syntax near "END": line 2 col 1 (at pos 32) SQLSTATE: HY000
'Hello'
"Hello"
1 row selected (overall time 4644 usec; server time 143 usec)

How to Convert Output of listagg() function into XMLTYPE

I have one stored Procedure P_FP_GET_PATTERN.I expect output in following format
PATTERN_ID |PATTERN_NAME | SHIFT
1 Pattern 1 A,B,C,B,A
2 Pattern 2 C,B,A,C
I'm getting this output in SYS_REFCURSOR ALL_RESULT_SET.I need to pass it in XML format.But the moment i put that output in ALL_RESULT_SET_XML which is my out parameter of stored procedure of XMLTYPE using ALL_RESULT_SET_XML:= XMLTYPE(ALL_RESULT_SET);
Im getting an error as
Error encountered: ORA-31061: XDB error: special char to escaped char conversion failed.
I`m getting this error due to column shown using LISTAGG() function.Anybody can please tell me how to handle this ?
My stored Procedure
create or replace
PROCEDURE P_FP_GET_PATTERN
(
ALL_RESULT_SET_XML OUT XMLTYPE,
P_MESSAGE_ALL OUT VARCHAR2
)
AS
V_ERROR VARCHAR2(2000);
ALL_RESULT_SET SYS_REFCURSOR;
BEGIN
OPEN ALL_RESULT_SET FOR
SELECT PM.PATTERN_ID ,PM.PATTERN_NAME,
LISTAGG(SM.SHIFT_NUMBER) WITHIN GROUP (ORDER BY PD.INSTANCE_DAY) "SHIFT"
FROM T_FP_PATTERN_MASTER PM,
T_FP_PATTERN_DETAILS PD,
T_FP_SHIFT_MASTER SM
WHERE SM.SHIFT_ID= PD.SHIFT_ID
AND PM.PATTERN_ID = PD.PATTERN_ID
GROUP BY PM.PATTERN_NAME,PM.PATTERN_ID;
--Adding output in XML output parameter
ALL_RESULT_SET_XML:= XMLTYPE(ALL_RESULT_SET);
EXCEPTION
WHEN OTHERS
THEN
V_ERROR := SUBSTR(SQLERRM,1,1000);
P_MESSAGE_ALL := 'Error encountered: '||V_ERROR ;
END;

Compilation error in Oracle PL/SQL

I have been staring at this hours trying to figure out why it won't run, and cannot see any syntax error which should stop this from compiling, but I am nonetheless getting the following errors:
Error(6,1): PL/SQL: SQL Statement ignored
Error(22,7): PL/SQL: ORA-00933: SQL command not properly ended
The function I am trying to create is as follows:
create or replace function caps_get_Uoffer_count_BD(ayrc in varchar2
,mcrc in varchar2)
return number
is
app_count number;
begin
select count(*)
from
(select distinct cap.cap_stuc,cap.cap_apfs , cap.cap_seqn from
intuit.srs_cap cap
,intuit.srs_apf apf
,intuit.srs_ioi ioi
where cap.cap_ayrc = ayrc
and cap.cap_mcrc = mcrc
and apf.apf_stuc = cap.cap_stuc
and apf.apf_seqn = cap.cap_apfs
and apf.apf_recd <= to_date('1501'||substr(ayrc,1,4),'DDMMYYYY')
and cap.cap_stuc = ioi.ioi_stuc
and cap.cap_mcrc = ioi.ioi_mcrc
and ioi.ioi_iodc ='PAPERLESS'
and cap.cap_stac like 'A%'
and cap.cap_idrc in ('U','UF','UI','UD','CFU','CFUF','CIUI','CIUF','CIUD','CIU','CFUI','CFUD'))
return(app_count);
end;
Database is Oracle 11g. Can anyone help?
Many thanks in advance

ORA-06502 Error when creating a view

I am trying to create a view on my production server which will not compile -- however, the view already exists on our test server with no error.
I am getting this error:
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 27
However, whats very confusing is the fact that the error itself points to the view column definition. I'm not really sure how to approach this, again considering the fact that the same routine exists in our test environment with no issues.
Here is the view, with a warning that it is pretty large:
CREATE OR REPLACE FORCE VIEW V2RPT.VW_DM
(
ACCESSION_LABEL,
RECEIVED_DATE,
ACCESSIONING_TS,
TTR_TUMOR_TYPE_INFO,
SPEC_TYPE,
TUMOR_TYPE,
TUMOR_SUBTYPE,
PRIM_MET,
TUMOR_SITE,
EXTRACT_DATE,
CELL_SOURCE_STATUS,
MIXTURE_STATUS,
PLATE_STATUS,
CS_TERM_REASON,
ASSAYS_ORDERED,
ASSAYS_REPORTED,
AOF_GEN_TS,
AOF_TRANS_TS,
AOF_PROC_TS,
FIRST_TERM_REPORT_TRANS_TS,
COMPLETE_WITHOUT_REPORT_TS,
RELATED_CELL_SOURCE,
FACILITY,
RELEASED_DATE,
IHC_DATE, --Error is happening here
T,
M,
N,
TUMOR_STAGE,
TUMOR_GRADE,
TUMOR_DIFF,
I_COUNT,
R_COUNT,
N_COUNT,
MIXTURE_ID,
PLATED_TS,
TREATED_TS,
FIXED_STAINED_TS,
SCANNED_TS,
COUNTED_TS,
ASSAYS_PLATED,
CELL_YIELD,
EXPLANTED_BY,
REPLATE,
AVG_CONTROL,
CELL_SUSPENSION_CREATOR,
CELL_SUSPENSION_TS,
IN_CULTURE_TS,
ENOUGH_CELLS_TS,
MIXTURE_ON_PLATE_TS,
TERM_MIXTURE_TS,
MIXTURE_TERM_REASON,
COMPLETE_TS,
VALIDATED_TS,
SALES_REP,
DRUG_SEL_TS,
DRUGS_ON_PANEL,
FINAL_PATH_COMP_TS,
PHYSICIAN,
CELL_SOURCE_TYPE_ID,
LXWXH,
PCT_SOLID,
PCT_FATTY,
PCT_FIBROUS,
PCT_BLOODY,
PCT_NECROTIC,
PCT_OTHER,
LESS_THAN_100MG,
OVERSIZED,
UNDERSIZED,
FLASK_TYPE,
VITROGEN_COATED,
AB_WASH_REQUIRED,
DIM_X,
DIM_Y,
DIM_Z,
MANUAL_PLATE,
LAB_SITE_ABBR,
REGION_TERRITORY,
MEDIUM_TYPE,
TUMOR_TYPE_FP,
TUMOR_TYPE_PP,
CR_ENTRY_CREATOR,
CR_ENTRY_CREATED_TS,
ICC_ENTRY_CREATOR,
ICC_ENTRY_CREATED_TS,
AOF_TRANS_CREATOR
)
AS
SELECT cs.accession_label,
cs.received_date,
cs.created_timestamp AS ACCESSIONING_TS,
PW.TTR_TUMOR_TYPE_INFO,
VW_CS.SPEC_TYPE,
VW_CS.TUMOR_TYPE,
VW_CS.TUMOR_SUBTYPE,
VW_CS.PRIM_MET,
VW_CS.TUMOR_SITE,
VW_CS.EXTRACT_DATE,
VW_CS.CELL_SOURCE_STATUS,
VW_CS.MIXTURE_STATUS,
VW_CS.PLATE_STATUS,
VW_CS.CS_TERM_REASON,
VW_CS.ASSAYS_ORDERED,
VW_CS.ASSAYS_REPORTED,
VW_CS.AOF_GEN_TS,
VW_CS.AOF_TRANS_TS,
VW_CS.AOF_PROC_TS,
VW_CS.FIRST_TERM_REPORT_TRANS_TS,
VW_CS.COMPLETE_WITHOUT_REPORT_TS,
VW_CS.RELATED_CELL_SOURCE,
VW_CS.VW_CS.FACILITY,
VW_CS.RELEASED_DATE,
VW_CS.IHC_DATE,
VW_CS.T,
VW_CS.M,
VW_CS.N,
VW_CS.TUMOR_STAGE,
VW_CS.TUMOR_GRADE,
VW_CS.TUMOR_DIFF,
VW_CS.I_COUNT,
VW_CS.R_COUNT,
VW_CS.N_COUNT,
MIXTURE.TERM_MC_MIXTURE_ID AS Mixture_ID,
MIXTURE.PLATED_TS,
MIXTURE.TREATED_TS,
MIXTURE.FIXED_STAINED_TS,
MIXTURE.SCANNED_TS,
MIXTURE.COUNTED_TS,
Mixture.Assays_Plated,
Mixture.CELL_YIELD,
Mixture.EXPLANTED_BY,
NVL (Mixture.REPLATE, 0) Replate,
Mixture.AVG_CONTROL,
Mixture.CELL_SUSPENSION_CREATOR,
Mixture.CELL_SUSPENSION_TS,
Mixture.IN_CULTURE_TS,
Mixture.ENOUGH_CELLS_TS,
Mixture.MIXTURE_ON_PLATE_TS,
Mixture.TERM_MIXTURE_TS,
Mixture.MIXTURE_TERM_REASON,
Mixture.COMPLETE_TS,
Mixture.VALIDATED_TS,
PW.SALES_REP,
PW.DRUG_SEL_TS,
PW.DRUGS_ON_PANEL,
PW.FINAL_PATH_COMP_TS,
PW.PHYSICIAN,
CS.CELL_SOURCE_TYPE_ID,
VW_CS.LXWXH,
VW_CS.PCT_SOLID,
VW_CS.PCT_FATTY,
VW_CS.PCT_FIBROUS,
VW_CS.PCT_BLOODY,
VW_CS.PCT_NECROTIC,
VW_CS.PCT_OTHER,
VW_CS.LESS_THAN_100MG,
VW_CS.OVERSIZED,
VW_CS.UNDERSIZED,
MIXTURE.FLASK_TYPE,
MIXTURE.VITROGEN_COATED,
VW_CS.AB_WASH_REQUIRED,
VW_CS.DIM_X,
VW_CS.DIM_Y,
VW_CS.DIM_Z,
MIXTURE.MANUAL_PLATE,
CS.LAB_SITE_ABBR,
V2.CRM_ACCOUNT_ADDRESS.STATE REGION_TERRITORY,
MIXTURE.MEDIUM_TYPE,
VW_CS.TUMOR_TYPE_FP,
VW_CS.TUMOR_TYPE_PP,
MIXTURE.CR_ENTRY_CREATOR,
MIXTURE.CR_ENTRY_CREATED_TS,
MIXTURE.ICC_ENTRY_CREATOR,
MIXTURE.ICC_ENTRY_CREATED_TS,
VW_CS.AOF_TRANS_CREATOR
FROM V2.cell_Source cs
INNER JOIN V2RPT.TEMP_DM_CS_TYPE
ON CS.CELL_SOURCE_TYPE_ID =
V2RPT.TEMP_DM_CS_TYPE.CELL_SOURCE_TYPE_ID
LEFT OUTER JOIN V2RPT.TEMP_DM_CS VW_CS
ON CS.CELL_SOURCE_ID = VW_CS.CELL_SOURCE_ID
LEFT OUTER JOIN V2RPT.TEMP_DM_MIXTURE MIXTURE
ON MIXTURE.cell_Source_id = CS.CELL_SOURCE_ID
LEFT OUTER JOIN V2RPT.VW_DM_PW PW
ON PW.cell_source_ID = cs.cell_source_ID
LEFT OUTER JOIN V2.CRM_ACCOUNT
ON V2.CRM_ACCOUNT.CRM_ACCOUNT_ID = CS.CRM_ACCOUNT_ID
LEFT OUTER JOIN ( SELECT MAX (
V2.CRM_ACCOUNT_ADDRESS.
CRM_ACCOUNT_ADDRESS_ID)
Max_AA_ID,
V2.CRM_ACCOUNT_ADDRESS.CRM_ACCOUNT_ID
FROM V2.CRM_ACCOUNT_ADDRESS
GROUP BY V2.CRM_ACCOUNT_ADDRESS.CRM_ACCOUNT_ID) Max_AA
ON Max_AA.CRM_ACCOUNT_ID = V2.CRM_ACCOUNT.CRM_ACCOUNT_ID
LEFT OUTER JOIN V2.CRM_ACCOUNT_ADDRESS
ON V2.CRM_ACCOUNT_ADDRESS.CRM_ACCOUNT_ADDRESS_ID =
max_aa.Max_AA_ID;
I'm a tad lost -- any ideas? I mean, there aren't even any variables to assign values to, so I don't know how the 'string buffer can be too small'
Appreciate the help.
Have you got any triggers on the database that are firing when the view is created? To me, the line error occurred at recursive SQL level 1 suggests an error in a trigger. Perhaps there's some kind of auditing trigger that is auditing objects being created and the view you created was too large for this trigger to cope with?
Here's a demonstration of how to generate an error similar to yours when creating a view. First, we create a trigger that causes a character string buffer too small error when you attempt to create something. Chances are that the trigger that appears to be causing your problem isn't quite this stupid:
SQL> create or replace trigger error_trigger
2 before create on database
3 declare
4 a varchar(1);
5 begin
6 a := '12';
7 end;
8 /
Trigger created.
Now, when we attempt to create a view, we get an error:
SQL> create view some_view as select * from dual;
create view some_view as select * from dual
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 4
This view has nothing to do with PL/SQL or character string buffers, nor does it even have a line 4, but we still get the above error because of the trigger we created. With this trigger, line 1 (declare) is the first line of the trigger itself, as opposed to the create trigger statement that creates it, so line 4 is the line a := '12';.
To track down this trigger, we can query the dba_triggers data dictionary view. In the example below, it turns up in the bottom row:
SQL> select trigger_name, trigger_type, owner from dba_triggers
2 where trigger_type in ('BEFORE EVENT', 'AFTER EVENT');
TRIGGER_NAME TRIGGER_TYPE OWNER
------------------------------ ---------------- ------------------------------
AW_DROP_TRG AFTER EVENT SYS
AW_TRUNC_TRG AFTER EVENT SYS
AW_REN_TRG AFTER EVENT SYS
XDB_PI_TRIG BEFORE EVENT SYS
SDO_DROP_USER AFTER EVENT MDSYS
SDO_ST_SYN_CREATE BEFORE EVENT MDSYS
SDO_TOPO_DROP_FTBL BEFORE EVENT MDSYS
ERROR_TRIGGER BEFORE EVENT LUKE

SQL Job Failing but not the stored procedure

EDIT 4/18:
I want to thank everyone who has answered so far. As a test I have set up a new job which has just one step in it,
EXECUTE p_CallLog_GetAbandonedCallsForCallList
This procedure itself runs just fine and reports no errors or warnings but will not run when executed as part of a job. The error I receive when running the job is:
Executed as user: NT AUTHORITY\SYSTEM. OLE DB provider 'SQLOLEDB' reported an error. [SQLSTATE 42000] (Error 7399) [SQLSTATE 01000] (Error 7312) OLE DB error trace
[OLE/DB Provider 'SQLOLEDB' IDBInitialize::Initialize returned 0x80004005: ].
[SQLSTATE 01000] (Error 7300). The step failed.
I have tried changing the run as user selection and every other selection I try results in an error of:
Executed as user: Db2WebCal. Remote access not allowed for Windows NT user activated
by SETUSER. [SQLSTATE 42000] (Error 7410). The step failed.
All of the users I have tried do have a local login setup on the linked server.
The p_CallLog_GetAbandonedCallsForCallList procedure is as follows:
CREATE PROCEDURE [dbo].[p_CallLog_GetAbandonedCallsForCallList]
AS
BEGIN
DECLARE #SrvrName varchar(255)
DECLARE #HoursOld int --only get abandoned call that are fresher than #HoursOld
SET #HoursOld = 2 /*was normal default */
SET #SrvrName = CAST(ServerProperty('MachineName') as varchar(255))
CREATE TABLE #tmpAbandonedCalls
(
[ID] INT NULL,
StartTime DateTime NULL,
CallerIDNumber varchar(255) NULL,
CallerIDCount INT NULL,
Holdtime INT NULL,
DIDNumber varchar(20) NULL,
CustomData varchar(255) NULL,
FromFirstName varchar(100) NULL,
FromLastName varchar(100) NULL,
CallType int NULL
)
IF #SrvrName <> 'ROME' BEGIN
INSERT INTO #tmpAbandonedCalls
SELECT
cl.[ID],
cl.StartTime,
cl.CallerIDNumber,
LastAbandonedCallID.cnt as CallerIDCount,
cl.HoldTime,
right(cl.DIDNumber,10) as DIDNumber,
REPLACE(right(left(cl.CustomData,charindex(';',cl.CustomData) - 1), len(left(cl.CustomData,charindex(';',cl.CustomData) - 1)) - charindex('=',cl.CustomData)) , ' NAME','') as CustomData,
cl.FromFirstName,
cl.FromLastName,
2 AS CallType -- T_L_CallType obctAbandoned
FROM
[StrataCS.Perceptionist.local].TVDB.dbo.CallLog CL LEFT OUTER JOIN
/*=============================================
This derived table lists the CallerID's and the most
recent Call Log ID for candidate calls
=============================================*/
(
SELECT
CallerIDNumber, Max(ID) as ID, count(*) as cnt
FROM
[StrataCS.Perceptionist.local].TVDB.dbo.CallLog CL
WHERE
--Last n days
--StartTime >= DATEADD(dd,-#DaysBack,CAST(CONVERT(VARCHAR(10),GETDATE(),112) as DATETIME))
--Get calls only from within the last two hours.
StartTime >= DATEADD(hh,-2,GETDATE())
AND
LEFT(CustomData,11) = 'CompanyName'
AND
CHARINDEX('Db2ID', CustomData) > 0
AND
CallerIDNumber <> ''
AND
Len(CallerIDNumber) = 10
AND
(cl.HoldTime > 0) --0 holdtime is generally an automated call that we will not want to call again
GROUP BY
CallerIDNumber
) as LastAbandonedCallID
ON
CL.CallerIDNumber = LastAbandonedCallID.CallerIDNumber
WHERE
--Last n days
--StartTime >= DATEADD(dd,-#DaysBack,CAST(CONVERT(VARCHAR(10),GETDATE(),112) as DATETIME))
--Get calls only from within the last two hours.
cl.StartTime >= DATEADD(hh,(-1 * #HoursOld),GETDATE())
AND
--determine abandoned calls
CASE
WHEN CL.Result IN (0, 3, 11) THEN 0
WHEN CL.Result IN (1, 2) THEN 1
WHEN CL.Result IN (4, 9) THEN 2
WHEN CL.Result = 5 THEN 3
WHEN CL.Result = 6 THEN 4
WHEN CL.Result = 8 THEN 5
WHEN CL.Result = 10 THEN 6
WHEN CL.Result = 12 THEN 7
WHEN CL.Result = 13 THEN 8
WHEN CL.Result = 14 THEN 9
ELSE -CL.Result
END = 0
--Calls which have hit the call queue will have both a CompanyName and Db2ID in custom data.
AND
LEFT(CustomData,11) = 'CompanyName'
AND
CHARINDEX('Db2ID', CustomData) > 0
AND
--omit calls with no caller id -- or from IGC 6143847400
(
CL.CallerIDNumber <> ''
--OR CL.CallerIDNumber = '6143847400'
)
AND
--make sure the caller id has 10 digits
Len(CL.CallerIDNumber) = 10
AND
--The abandoned call must be the most recent call from this caller id
--CL.ID >= isnull(LastAbandonedCallID.ID,-#DaysBack)
CL.ID >= isnull(LastAbandonedCallID.ID,-1)
AND
(CL.HoldTime > 0) --0 holdtime is generally an automated call that we will not want to call again
ORDER BY
--sort by call time, most recent first.
StartTime DESC
-- Company has opted out of the Abandoned Callback program
DELETE #tmpAbandonedCalls
FROM
#tmpAbandonedCalls tmp
INNER JOIN dbo.T_CompanyPhoneSetup cps
on tmp.DIDNumber = cps.DID
INNER JOIN T_CompanyAbandonedCallbackOptOut aco
ON cps.CompanyID = aco.CompanyID
AND
aco.OptOutIsActive = 1
--Delete calls that have had a terminating outcome or have been returned within the last 20 minutes
DELETE #tmpAbandonedCalls
FROM
#tmpAbandonedCalls
INNER JOIN
(
SELECT
c.CallLogID
FROM
T_Call c (nolock)
INNER JOIN #tmpAbandonedCalls tmp
on tmp.ID = c.CallLogID
LEFT OUTER JOIN T_L_Need n
ON c.NeedID = n.NeedID
LEFT OUTER JOIN T_L_Outcome o
ON c.OutcomeID = o.OutcomeID
LEFT OUTER JOIN dbo.T_L_CallCampaignDetailStatus ccds
ON o.CCDetailStatusID = ccds.CCDetailStatusID
LEFT OUTER JOIN dbo.T_Company co
ON c.CompanyID = co.CompanyID
LEFT OUTER JOIN dbo.T_L_ProductLine pl
ON co.ProductLineID = pl.ProductLineID
LEFT OUTER JOIN T_CompanyAbandonedCallbackOptOut aco
ON (c.CompanyID = aco.CompanyID) and (aco.OptOutIsActive = 1)
GROUP BY
c.CallLogID
HAVING
--Calls that have an outcome that include at least one terminating outcome
(SUM(CAST(isnull(ccds.IsTerminal,0) as INT)) > 0)
OR
(
--Calls that have been returned less than 20 minutes ago
(SUM(CAST(isnull(ccds.IsTerminal,0) as INT)) = 0)
AND
GETDATE() <= DATEADD(mi,20,Max(c.EnteredOn))
)
OR
(
--Calls for Perceptionist Lite product line
(MAX(co.ProductLineID) = 2) -- Perceptionist Lite
)
) LastCall
ON
#tmpAbandonedCalls.[ID] = LastCall.CallLogID
END
INSERT INTO T_OutboundCallList
(TrackingID, Company, CompanyDID, Phone, CallType)
SELECT
#tmpAbandonedCalls.[ID],
#tmpAbandonedCalls.CustomData,
#tmpAbandonedCalls.DIDNumber,
#tmpAbandonedCalls.CallerIDNumber,
#tmpAbandonedCalls.CallType
FROM
#tmpAbandonedCalls
ORDER BY
StartTime
END
GO
ORIGINAL:
I have the following stored procedure that is used to fill a table with values.
PROCEDURE [dbo].[p_OutboundCallList_Create]
AS
BEGIN
TRUNCATE TABLE T_OutboundCallList
EXECUTE p_LeadVendor_GetCallsForCallList
EXECUTE p_CallCampaign_GetCallsForCallList
EXECUTE p_CallLog_GetAbandonedCallsForCallList
EXECUTE p_NoSaleFollowUp_GetCallsForCallList
END
Running this works fine and the table is filled. After creating a job and adding the following step:
EXEC p_OutboundCallList_Create
The job fails with the following error message:
Executed as user: NT AUTHORITY\SYSTEM. Warning: Null value is eliminated
by an aggregate or other SET operation. [SQLSTATE 01003] (Message 8153)
Warning: Null value is eliminated by an aggregate or other SET operation.
[SQLSTATE 01003] (Message 8153) OLE DB provider 'SQLOLEDB' reported an error.
[SQLSTATE 42000] (Error 7399) [SQLSTATE 01000] (Error 7312) OLE DB error trace
[OLE/DB Provider 'SQLOLEDB' IDBInitialize::Initialize returned 0x80004005: ].
[SQLSTATE 01000] (Error 7300). The step failed.
If I comment out the line
EXECUTE p_CallLog_GetAbandonedCallsForCallList
..the job runs fine. This stored procedure (p_CallLog_GetAbandonedCallsForCallList) does rely on a linked server and runs fine by itself and also runs fine when I run p_OutboundCallList_Create. It only fails when I run it as part of a job. I have tried running as a different user (sa, benderle, etc.) and always get the same result (failed).
"Null value is eliminated by an aggregate or other SET operation" is a SQL Server warning, which means you won't see it in the output if you run your query and this warning is raised (switch to the "Messages" tab in SQL Server Management Studio to see this).
Although it's a warning, presumably any warnings in a SQL job cause the job to error out. Fix the p_CallLog_GetAbandonedCallsForCallList procedure so it doesn't raise that warning and you job will work as expected.
I woulf be interested in seeing the code in p_CallLog_GetAbandonedCallsForCallList, as it may explain more as to why this is happening for the user NT AUTHORITY\SYSTEM.
The message occurs when you perform an aggregation (e.g. sum(), max(), count() on a data set that has a null in it).
To fix this, you may need to put an ISNULL() around the field in question, or use an INNER JOIN instead of a LEFT or RIGHT JOIN.
To disable warning that throw error in Sql Server Agent tasks.
The tasks that are launched from the SQL SERVER AGENT (scheduled), give an error, if there is a warning of the style:
"Null value is eliminated by an aggregate or other SET operation"
This message can be disabled by SET ANSI_WARNING OFF
But in some cases, there are sql statements that require this value to be on to avoid errors like:
Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query
Therefore, there is no other solution than to prevent SQL SERVER AGENT from considering it an error.
This can be achieved by modifying the values ​​in the REGISTRY (REGEDIT)
Modify the entries, depending on your version of SQL SERVER:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\SQLServerAgent
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.SQL2012\SQLServerAgent
Add as 'no error' the message id you want to disable: 7405