See This:
I want to call it by Tquery and gain the deffient return value.
But Everytime I got 0(in delphi) instead of 22(in ISQL).
>>
create procedure cp_pre_store2001(
@clinicno int,
@prescno int,
@mno int,
@ecount int,
@unit char(4),
@dosage int,
@usageno int,
@freq int,
@type int,
@result int output
)
as
declare @each int,@eachbase int,@countbase int,@rel int,@temp int
declare @serialno int
declare @batchno char(6)
declare @sno int
declare @continue int
declare @uprice money
begin transaction store
if not exists(
select PRE_STORE from M_STORE2001 holdlock
where M_NO=@mno
and PRE_STORE>=@ecount)
begin
rollback tran
select @result=10
end
update M_STORE2001 set PRE_STORE=PRE_STORE-@ecount where M_NO=@mno
if @@rowcount=0
begin
rollback tran
select @result=21
end
select PRE_STORE from M_BATCH2001 holdlock where M_NO=@mno
select @uprice=R_PRICE,@rel=RELATION from MPRICE
where M_NO=@mno
and BATCH_NO=@batchno
and BIG_UNIT=@unit
if @@rowcount=0
begin
rollback tran
select @result=22
end
else
select @countbase=@rel*@ecount
while @countbase>0
begin
select @continue=1
select @eachbase=PRE_STORE,@batchno=BATCH_NO from M_BATCH2001
where M_NO=@mno and PRE_STORE<>0 order by TOINVALID desc
if @eachbase>=@countbase
begin
select @each=@ecount
select @ecount=0
select @eachbase=@countbase
select @countbase=0
end
else
begin
if @type=0
begin
select @temp=@ecount-@each
select @ecount=@temp
select @temp=@countbase-@eachbase
select @countbase=@temp
end
else
select @continue=0
end
if @continue=1
begin
update M_BATCH2001 set PRE_STORE=PRE_STORE-@eachbase
where M_NO=@mno
and BATCH_NO=@batchno
if @@rowcount=0
begin
rollback tran
select @result=23
end
select @uprice=R_PRICE from MPRICE
where M_NO=@mno
and BATCH_NO=@batchno
and BIG_UNIT=@unit
if @@rowcount=0
begin
rollback tran
select @result=24
end
select @serialno=max(SERIAL_NO) from MSTOCK2001 holdlock
if @@rowcount=0
begin
select @serialno=0
end
insert into OUTPMEDICINES(CLINIC_NO,PRESC_NO,SNO,FEE_NO,M_NO,
BATCH_NO,UNIT,UNITPRICE,QUANTITY,DOSAGE,USAGE_NO,FREQUENCY)
select @clinicno,@prescno,@sno,FEE_NO,@mno,
@batchno,@unit,@uprice,@each,@dosage,@usageno,@freq
from MEDCINE
where M_NO=@mno
select @result=1
end /* end of continue */
end
commit transaction
>>>>
The calling in Delphi write like this:
>>>>
qryCp.Close;
qryCp.SQL.Text := 'declare @rlt int ';
qryCp.SQL.Text := qryCp.SQL.Text+'exec cp_pre_store'+frmPublicData.P_MSRC_CODE
+'('+edtClinic_No.Text+','+edtPresc_No.Text+','
+curM_No+','+edtQuantity.Text+',"'
+cbbxUnits.Text+'",'+Dosagestr+','
+Usagestr+','+FreqTypeStr+',1,@res=@rlt)';
qryCp.SQL.Add(' select @rlt as RT');
qryCp.Open;
rno := qryCp.FieldByname('RT').AsInteger;
>>
The rno is integer which I want to get the return value.