if exists (select * from sysobjects where name = 'ARGotherdepartUpdate' ) drop procedure ARGotherdepartUpdate GO create procedure ARGotherdepartUpdate @function_id smallint, @departno smallint , --营业部编号 @depa_name varchar(60), --营业部名称 @sname varchar(20), --营业部简称 @return int output with encryption as 。 if @function_id = 100 begin select * from ARGotherdepart order by departno --where departno = @departno if @@rowcount < 1 set @return =-100 end set @return =100
老大, create procedure ARGotherdepartUpdate @function_id smallint, @departno smallint , --营业部编号 @depa_name varchar(60), --营业部名称 @sname varchar(20) --营业部简称 with encryption as 。 if @function_id = 100 begin select * from ARGotherdepart order by departno --where departno = @departno if @@rowcount < 1 return -100 return 100--这里面才是@function_id = 100能够近来的,不会到外面去返回 end
if exists (select * from sysobjects where name = 'ARGotherdepartUpdate' ) drop procedure ARGotherdepartUpdate GO create procedure ARGotherdepartUpdate @function_id smallint, @departno smallint , --营业部编号 @depa_name varchar(60), --营业部名称 @sname varchar(20), --营业部简称 @return int output with encryption as 。 if @function_id = 100 begin select * from ARGotherdepart order by departno --where departno = @departno if @@rowcount < 1 set @return =-100 end set @return =100 EXECUTE @return_status = procedure_name
谢谢各位! to: caiyunxia(monkey) ,存储过程是不能改的 to:CrazyFor(蚂蚁) ,过程里面的return 后面都是常数,不可能是空值的
create procedure ARGotherdepartUpdate @function_id smallint, @departno smallint , @depa_name varchar(60), @sname varchar(20) with encryption as if @function_id = 102 begin delete ARGotherdepart where departno = @departno if @@error <> 0 return -100 end if @function_id = 101 begin if( not exists ( select * from ARGotherdepart where departno = @departno ) ) begin insert into ARGotherdepart ( departno, depa_name, sname ) values( @departno, @depa_name, @sname ) if( @@error <> 0 ) return -100 end else begin update ARGotherdepart set depa_name = @depa_name, sname = @sname where departno = @departno if @@error <> 0 return -100 end end if @function_id = 100 begin select * from ARGotherdepart order by departno if @@rowcount < 1 return -100 end return 100
drop procedure ARGotherdepartUpdate
GO
create procedure ARGotherdepartUpdate @function_id smallint,
@departno smallint , --营业部编号
@depa_name varchar(60), --营业部名称
@sname varchar(20), --营业部简称
@return int output
with encryption
as
。
if @function_id = 100
begin
select * from ARGotherdepart order by departno --where departno = @departno
if @@rowcount < 1
set @return =-100
end
set @return =100
create procedure ARGotherdepartUpdate @function_id smallint,
@departno smallint , --营业部编号
@depa_name varchar(60), --营业部名称
@sname varchar(20) --营业部简称
with encryption
as
。
if @function_id = 100
begin
select * from ARGotherdepart order by departno --where departno = @departno
if @@rowcount < 1
return -100
return 100--这里面才是@function_id = 100能够近来的,不会到外面去返回
end
当用于存储过程时,RETURN 不能返回空值。如果过程试图返回空值(例如,使用 RETURN @status 且 @status 是 NULL),将生成警告信息并返回 0 值。在执行当前过程的批处理或过程内,可以在后续 Transact-SQL 语句中包含返回状态值,但必须以下列格式输入:EXECUTE @return_status = procedure_name
exec @i =ARGotherdepartUpdate 100,0,NULL,NULL
select @i
-----------
100
的正确结果,用程序语言怎么得到这个值呢,我用
Trade_DM->StoredProc1->Close();
Trade_DM->StoredProc1->UnPrepare();
Trade_DM->StoredProc1->DatabaseName = sDataBaseName ;
Trade_DM->StoredProc1->StoredProcName = sDataBaseName+".."+sp_name;
Trade_DM->StoredProc1->Params->Clear();
Trade_DM->StoredProc1->Params->Add()->Index=0;
Trade_DM->StoredProc1->Params->Items[0]->Name ="result";
Trade_DM->StoredProc1->Params->Items[0]->DataType = ftInteger;
Trade_DM->StoredProc1->Params->Items[0]->ParamType = ptResult;
...其它几个参数赋值
Trade_DM->StoredProc1->Prepare();
Trade_DM->StoredProc1->ExecProc();
iReturn = Trade_DM->StoredProc1->ParamByName ("result")->AsInteger;得到的 iReturn 总是为0的
drop procedure ARGotherdepartUpdate
GO
create procedure ARGotherdepartUpdate @function_id smallint,
@departno smallint , --营业部编号
@depa_name varchar(60), --营业部名称
@sname varchar(20), --营业部简称
@return int output
with encryption
as
。
if @function_id = 100
begin
select * from ARGotherdepart order by departno --where departno = @departno
if @@rowcount < 1
set @return =-100
end
set @return =100
EXECUTE @return_status = procedure_name
to: caiyunxia(monkey) ,存储过程是不能改的
to:CrazyFor(蚂蚁) ,过程里面的return 后面都是常数,不可能是空值的
with encryption
as
if @function_id = 102
begin
delete ARGotherdepart where departno = @departno
if @@error <> 0
return -100
end
if @function_id = 101
begin
if( not exists ( select * from ARGotherdepart
where departno = @departno ) )
begin
insert into ARGotherdepart ( departno, depa_name, sname )
values( @departno, @depa_name, @sname )
if( @@error <> 0 )
return -100
end
else
begin
update ARGotherdepart
set depa_name = @depa_name,
sname = @sname
where departno = @departno
if @@error <> 0
return -100
end
end
if @function_id = 100
begin
select * from ARGotherdepart order by departno
if @@rowcount < 1
return -100
end
return 100
你为什么不用输出参数呢?