您的位置:首页 > 编程语言 > Delphi

在delphi中取存储过程的返回值

2009-11-28 15:48 267 查看
在delphi中取存储过程的返回值

Close;

SQL.Clear;

SQL.Text:='declare @ReturnCount int exec Pr_SelStockHead '''+StockNo+''',@ReturnCount output select @ReturnCount';

open;

CountNO:=fields[0].value;

cxtxtdtNameCSHYH.Text:=IntToStr(CountNO);

在sql语句里面 如果有返回值的话,可以是用return 返回,,其他的都是参数返回,如果取参数的话 从 Parameters[1].Value 开始,如果取return 的返回值 要用Parameters[0].Value

调用存储过程的方法,用adodataset控件

function TfrmPower_Cut.HasNewPowerCutInfo: Boolean;

begin

Result := False;

with spPower_Cut do //spPower_Cut为Tadostoredproc控件

begin

Close;

ProcedureName := 'p_Has_PowerCut_Info';

with Parameters do

begin

Clear;

Refresh;

ParamByName('@BiggestID').Direction
:= pdInputOutput;

ParamByName('@BiggestID').Value
:= FPower_Cut_ID_Refresh;

ParamByName('@NoProcess').Direction
:= pdInputOutput;

ParamByName('@NoProcess').Value
:= FNoProcess;

ParamByName('@IsPassTimeAndNoProc').Direction
:= pdInputOutput;

ParamByName('@IsPassTimeAndNoProc').Value
:= FIsPassTimeAndNoProc;

ParamByName('@IsNearestTime').Direction
:= pdInputOutput;

ParamByName('@IsNearestTime').Value
:= FIsNearestTime;

ParamByName('@IsDelete').Direction
:= pdInputOutput;

ParamByName('@IsDelete').Value
:= FIsNearestTime;

ParamByName('@Hour').Value
:= 3;

end;

Prepared;

try

ExecProc;

if Parameters[0].Value <> FPower_Cut_ID_Refresh then

begin

FPower_Cut_ID_Refresh := Parameters[1].Value;

Result := True;

end;

if Parameters[2].Value <> FNoProcess then

begin

FNoProcess := Parameters[2].Value;

Result := True;

end;

if Parameters[3].Value <> FIsPassTimeAndNoProc then

begin

FIsPassTimeAndNoProc := Parameters[3].Value;

Result := True;

end;

if Parameters[4].Value <> FIsNearestTime then

begin

FIsNearestTime := Parameters[4].Value;

Result := True;

end;

if Parameters[5].Value <> FIsDelete then

begin

FIsDelete := Parameters[5].Value;

Result := True;

end;

except

on e: Exception do

ShowMessage(e.Message);

end;

end;

end;

存储过程

/*

功能: 判断数据库内是否有新的呼叫中心停电信息

参数: @BiggestID 客户端最大的记录ID,如果小于当前表中的ID,则返回最大的ID,客户端据此判断是否刷新

返回值: 无

*/

ALTER procedure p_Has_PowerCut_Info @BiggestID bigint=0 output, @NoProcess int=0 output,

@IsPassTimeAndNoProc int=0 output, @IsNearestTime int=0 output, @IsDelete int=0 output, @Hour int=3 as

begin

declare @tmp_ID bigint,@tmp_NoProcess int

select @tmp_ID=Power_Cut_ID from Power_Cut

if (@@error=0) and (@@rowcount>0)

if @tmp_id>@BiggestID

set @BiggestID=@tmp_ID

select @tmp_NoProcess=count(*) from Power_Cut where PC_ProcType=0

if (@@error=0) and (@@rowcount>0)

set @NoProcess=@tmp_NoProcess

--超过发送时间未处理

select @IsPassTimeAndNoProc=count(case when (getdate()>PC_StartTime and PC_ProcType=0) then 1 end) from Power_Cut

--距离发送时间还有3小时未处理

select @IsNearestTime=count(case when (DATEDIFF(minute, getdate(),
PC_StartTime)>=0 and DATEDIFF(minute, getdate(),
PC_StartTime)<@Hour*60

and PC_ProcType=0) then 1 end) from Power_Cut

select @IsDelete=count(*) from Power_Cut where PC_State=2

return @BiggestID

end

return 返回的是正确或错误的标志,比如 100: 成功 0: 失败(未知原因) 1: 参数错误 2: .... 然后参数里面返回具体需要的数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: