I am very familiar with using stored procedures in reports but have never seen the behavior you are stating ... I am not quite sure what you mean by getting "Expression" instead of field list.
Without seeing your procedure, I'd guess that you're either using variables or aggregates in your final SELECT statement, but aren't aliasing the columns. If my guess is close, your statement should be written like this:
SELECT MyVar = @MyVariable, MySum = SUM(Table.Field)
FROM Table
ALTER procedure DBA.rep_contmissingOB2(in @Enter_date date) /* parameter, ... */
/* RESULT ( column_name, ... ) */
begin
declare p1 integer;
declare p2 integer;
declare p3 integer;
declare p4 integer;
declare p5 varchar(150);
//Find all outbound containers with missing contents
create table #cont(
ordno varchar(30) null,
hdate date null,
origin varchar(30) null,
orgdesc varchar(50) null default '',
dest varchar(30) null,
destdesc varchar(50) null default '',
htype varchar(10) null,
status varchar(5) null,
pkgid varchar(50) null,
serial varchar(50) null,
);
insert into #cont(ordno,hdate,origin,dest,htype,status,pkgid,serial)
select header.ordernumber,cast("date" as date),origin,destination,header.type,status,detail.packageid,serial from
header join detail on header.ordernumber = detail.ordernumber left outer join
shipmenttypes on header.type = shipmenttypes.typecode left outer join
content on header.ordernumber = content.ordernumber left outer join
shipmentnotes on content.serial = shipmentnotes.packageid where
cast("date" as date) = @Enter_date and shipmenttypes.hascontent = '1' and status = 'D' and shipmentnotes.note = 'Package is Missing from Shipment';
create table #tmp2(
usr varchar(10) null,
tstmp timestamp null,
note2 varchar(150) null,
);
for trloop as transcurs dynamic scroll cursor for
select serial from #cont do
insert into #tmp2(usr,tstmp,note2)
select top 1 userid,"timestamp",note from
audittrail where eventnumber = '28' and note like('%'+serial+'%') order by
"timestamp" desc end for;
commit work;
create table #tmp3(
pkgid2 varchar(30) null,
lstusr varchar(15) null,
lststmp timestamp null,
);
for tr2loop as trans2curs dynamic scroll cursor for
select * from #tmp2 do
set p1=patindex('%-%',note2);
set p3=(p1+1);
set p2=locate(note2,'-',p3);
set p4=(p2-p3);
set p5=note2;
//update #tmp2
//set serno = substr(p5,p3,p4) ;
insert into #tmp3(pkgid2,lstusr,lststmp) values(
substr(p5,p3,p4),usr,tstmp) end for;
commit work;
select * from
#cont left outer join #tmp3 on #cont.serial = #tmp3.pkgid2
end
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.