有两个变量,和一个返回值。
我怎么用pB把这两个变量传给存储过程,然后把返回值显示出来。
存储过程中的两个变量分别是@P_date nvchar(10),@P_user nvchar(10)
返回值是一个字符串 如‘12345’
如何实现
12 个解决方案
#1
DECLARE sp_aa PROCEDURE FOR lp_cc (:P_date nvchar,P_user nvchar);
EXECUTE sp_ckz;/执行存储过程
CLOSE sp_ckz;//关闭
sp_aa 是自己随便取的一个名字
lp_cc 是数据库里的存储过程的名字
#2
DECLARE sp_aa PROCEDURE FOR lp_cc (:P_date nvchar,P_user nvchar);
EXECUTE sp_aa;/执行存储过程
CLOSE sp_aa;//关闭
不好意思 刚才没写好
sp_aa 是自己随便取的一个名字
lp_cc 是数据库里的存储过程的名字
#3
第一句后面还少一个冒号
DECLARE sp_aa PROCEDURE FOR lp_cc (:P_date nvchar,:P_user nvchar);
#4
string ls_reture
string ls_user
date ld_date
DECLARE p1 PROCEDURE FOR procedure_name
@P_date = :ld_date,@P_user=:ls_user;
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
string ls_user
date ld_date
DECLARE p1 PROCEDURE FOR procedure_name
@P_date = :ld_date,@P_user=:ls_user;
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
#5
我的存储过程如下,为什么一直报‘执行错误’呢
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[Update_TR_1]
@P_date char(10),
@P_user char(10)
--@P_shift char(10)
AS
SET NOCOUNT ON;
--BEGIN
--硬代码用于测试
--declare @P_date datetime ,@P_user nvarchar(10) ,@P_shift nvarchar(5)
--set @P_date=CONVERT(varchar,'20101213',120)
--set @P_user='chris'
--set @P_shift='15'
declare @ST int,@id int,@prperiod int,@shift int,@prday datetime,@employee int,@material int,@weight real,@regtime datetime,@rtype smallint,
@maxid int,@count int,@check_count int,@check_maxid int,@maxupdate int,
@Ins_row int,@minid int,@OP_shift nchar(5),@P_name nchar(20)
Set @Ins_row=0
set @P_name='PAOS_trim_regs'
---写状态到updat表中 state=true
-----------------------------取出上一次成功同步的数据------------
declare starde cursor-------------------------------------定义游标“starde”
for Select updateid,minid,op_shift From PAOS_TEMP.dbo.update_2 where updatename='PAOS_trim_regs'---
open starde
fetch next from starde into @ST,@minid,@OP_shift
close starde
DEALLOCATE starde
-----取出最新数据----
declare R_x cursor
for select id,prperiod,shift,prday,employee,material,weight,regtime,rtype from pacifcandes503.dbo.trim_regs where id >@minid and id<=@ST and prday='20101213' Order by id
open R_x
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
declare @str varchar(300)
while @@fetch_status=0
begin
set @str='Insert into PAOS_TEMP.dbo.PAOS_trim_regs (id,prperiod,shift,prday,employee,material,weight,regtime,rtype,state) Values('+rtrim(@id)+','+rtrim(@prperiod)+','+char(39)+rtrim(@shift)+char(39)+','+char(39)+rtrim(@prday)+char(39)+','+char(39)+ltrim(@employee)+char(39)+','+rtrim(@material)+','+rtrim(@weight)+','+char(39)+rtrim(@regtime)+char(39)+','+rtrim(@rtype)+',0)'
exec(@str)
-- use pacifcandes503
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
Set @Ins_row=@Ins_row+1 ------计数器,每插入一条,加1
-----------------纪录更新id值---------------
set @str='Update PAOS_TEMP.dbo.update_2 Set minid='+char(39)+rtrim(@id)+char(39)+' where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
end
close R_x
DEALLOCATE R_x
-----------------------------校验数据量------------------
print'----------------------'
print 'MAXID'+rtrim(@ST)
print 'minid='+rtrim(@minid)
print 'ins_row='+rtrim(@ins_row)
print'-----------------------'
---------------------------清理已同步数据----------------
--USE PAOS_TEMP
set @str='Delete From PAOS_TEMP.dbo.PAOS_trim_regs where state=1' -----<<须更改表名
exec(@str)
---写更新时间
set @str='Update PAOS_TEMP.dbo.update_2 Set end_time=CONVERT(varchar,getdate(),120) where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
--写日志
set @str='insert into PAOS_TEMP.dbo.ins_log_2 (Minid,Maxid,OP_Count,OP_Tab_Name,OP_User,OP_shift,OP_OPtion) values ('+char(39)+ltrim(@minid)+char(39)+','+char(39)+ltrim(@ST)+char(39)+','+char(39)+ltrim(@ins_row)+char(39)+','+char(39)+rtrim(@P_name)+char(39)+','+char(39)+rtrim(@P_user)+char(39)+','+char(39)+rtrim(@oP_shift)+char(39)+','+char(39)+rtrim('Update')+char(39)+')'
exec(@str)
return @Ins_row
--end
#6
自己到查询分析器里调试吧
#7
#8
我又修改了一下存储过程,如下,
PB代码如下:
integer ls_reture
string ls_user
string ld_date
ld_date='20101216'
ls_user='chris'
DECLARE p1 PROCEDURE FOR dbo.Update_TR_1
@P_date = :ld_date, @P_user=:ls_user ,@ins_row=:ls_reture output,
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
messagebox("OK",ls_reture)
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
为什么结果一直是0呢
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
create PROCEDURE [dbo].[Update_TR_1]
@P_date varchar(10),
@P_user varchar(10),
@Ins_row int output
AS
SET NOCOUNT ON;
--BEGIN
--硬代码用于测试
--declare @P_date datetime ,@P_user nvarchar(10) ,@P_shift nvarchar(5)
--set @P_date=CONVERT(varchar,'20101213',120)
--set @P_user='chris'
--set @P_shift='15'
declare @ST int,@id int,@prperiod int,@shift int,@prday datetime,@employee int,@material int,@weight real,@regtime datetime,@rtype smallint,
@maxid int,@count int,@check_count int,@check_maxid int,@maxupdate int,
@minid int,@OP_shift nchar(5),@P_name nchar(20)
Set @Ins_row=0
set @P_name='PAOS_trim_regs'
---写状态到updat表中 state=true
-----------------------------取出上一次成功同步的数据------------
declare starde cursor-------------------------------------定义游标“starde”
for Select updateid,minid,op_shift From PAOS_TEMP.dbo.update_2 where updatename='PAOS_trim_regs'---
open starde
fetch next from starde into @ST,@minid,@OP_shift
close starde
DEALLOCATE starde
-----取出最新数据----
declare R_x cursor
for select id,prperiod,shift,prday,employee,material,weight,regtime,rtype from pacifcandes503.dbo.trim_regs where id >@minid and id<=@ST and prday=@P_date Order by id
open R_x
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
declare @str varchar(300)
while @@fetch_status=0
begin
set @str='Insert into PAOS_TEMP.dbo.PAOS_trim_regs (id,prperiod,shift,prday,employee,material,weight,regtime,rtype,state) Values('+rtrim(@id)+','+rtrim(@prperiod)+','+char(39)+rtrim(@shift)+char(39)+','+char(39)+rtrim(@prday)+char(39)+','+char(39)+ltrim(@employee)+char(39)+','+rtrim(@material)+','+rtrim(@weight)+','+char(39)+rtrim(@regtime)+char(39)+','+rtrim(@rtype)+',0)'
exec(@str)
-- use pacifcandes503
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
Set @Ins_row=@Ins_row+1 ------计数器,每插入一条,加1
-----------------纪录更新id值---------------
set @str='Update PAOS_TEMP.dbo.update_2 Set minid='+char(39)+rtrim(@id)+char(39)+' where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
end
close R_x
DEALLOCATE R_x
-----------------------------校验数据量------------------
print'----------------------'
print 'MAXID'+rtrim(@ST)
print 'minid='+rtrim(@minid)
print 'ins_row='+rtrim(@ins_row)
print'-----------------------'
---------------------------清理已同步数据----------------
--USE PAOS_TEMP
set @str='Delete From PAOS_TEMP.dbo.PAOS_trim_regs where state=1' -----<<须更改表名
exec(@str)
---写更新时间
set @str='Update PAOS_TEMP.dbo.update_2 Set end_time=CONVERT(varchar,getdate(),120) where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
--写日志
set @str='insert into PAOS_TEMP.dbo.ins_log_2 (Minid,Maxid,OP_Count,OP_Tab_Name,OP_User,OP_shift,OP_OPtion) values ('+char(39)+ltrim(@minid)+char(39)+','+char(39)+ltrim(@ST)+char(39)+','+char(39)+ltrim(@ins_row)+char(39)+','+char(39)+rtrim(@P_name)+char(39)+','+char(39)+rtrim(@P_user)+char(39)+','+char(39)+rtrim(@oP_shift)+char(39)+','+char(39)+rtrim('Update')+char(39)+')'
exec(@str)
return
PB代码如下:
integer ls_reture
string ls_user
string ld_date
ld_date='20101216'
ls_user='chris'
DECLARE p1 PROCEDURE FOR dbo.Update_TR_1
@P_date = :ld_date, @P_user=:ls_user ,@ins_row=:ls_reture output,
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
messagebox("OK",ls_reture)
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
为什么结果一直是0呢
#9
#10
多fetch几次试试
fetch p1 into :ls_reture ;此句可能获取的是return的默认值0
fetch p1 into :ls_reture ;此句可能获取output参数
fetch p1 into :ls_reture ;此句可能获取的是return的默认值0
fetch p1 into :ls_reture ;此句可能获取output参数
#11
不行,取不到返回值,
#12
设置sqlca.AutoCommit = true试试
#1
DECLARE sp_aa PROCEDURE FOR lp_cc (:P_date nvchar,P_user nvchar);
EXECUTE sp_ckz;/执行存储过程
CLOSE sp_ckz;//关闭
sp_aa 是自己随便取的一个名字
lp_cc 是数据库里的存储过程的名字
#2
DECLARE sp_aa PROCEDURE FOR lp_cc (:P_date nvchar,P_user nvchar);
EXECUTE sp_aa;/执行存储过程
CLOSE sp_aa;//关闭
不好意思 刚才没写好
sp_aa 是自己随便取的一个名字
lp_cc 是数据库里的存储过程的名字
#3
第一句后面还少一个冒号
DECLARE sp_aa PROCEDURE FOR lp_cc (:P_date nvchar,:P_user nvchar);
#4
string ls_reture
string ls_user
date ld_date
DECLARE p1 PROCEDURE FOR procedure_name
@P_date = :ld_date,@P_user=:ls_user;
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
string ls_user
date ld_date
DECLARE p1 PROCEDURE FOR procedure_name
@P_date = :ld_date,@P_user=:ls_user;
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
#5
我的存储过程如下,为什么一直报‘执行错误’呢
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[Update_TR_1]
@P_date char(10),
@P_user char(10)
--@P_shift char(10)
AS
SET NOCOUNT ON;
--BEGIN
--硬代码用于测试
--declare @P_date datetime ,@P_user nvarchar(10) ,@P_shift nvarchar(5)
--set @P_date=CONVERT(varchar,'20101213',120)
--set @P_user='chris'
--set @P_shift='15'
declare @ST int,@id int,@prperiod int,@shift int,@prday datetime,@employee int,@material int,@weight real,@regtime datetime,@rtype smallint,
@maxid int,@count int,@check_count int,@check_maxid int,@maxupdate int,
@Ins_row int,@minid int,@OP_shift nchar(5),@P_name nchar(20)
Set @Ins_row=0
set @P_name='PAOS_trim_regs'
---写状态到updat表中 state=true
-----------------------------取出上一次成功同步的数据------------
declare starde cursor-------------------------------------定义游标“starde”
for Select updateid,minid,op_shift From PAOS_TEMP.dbo.update_2 where updatename='PAOS_trim_regs'---
open starde
fetch next from starde into @ST,@minid,@OP_shift
close starde
DEALLOCATE starde
-----取出最新数据----
declare R_x cursor
for select id,prperiod,shift,prday,employee,material,weight,regtime,rtype from pacifcandes503.dbo.trim_regs where id >@minid and id<=@ST and prday='20101213' Order by id
open R_x
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
declare @str varchar(300)
while @@fetch_status=0
begin
set @str='Insert into PAOS_TEMP.dbo.PAOS_trim_regs (id,prperiod,shift,prday,employee,material,weight,regtime,rtype,state) Values('+rtrim(@id)+','+rtrim(@prperiod)+','+char(39)+rtrim(@shift)+char(39)+','+char(39)+rtrim(@prday)+char(39)+','+char(39)+ltrim(@employee)+char(39)+','+rtrim(@material)+','+rtrim(@weight)+','+char(39)+rtrim(@regtime)+char(39)+','+rtrim(@rtype)+',0)'
exec(@str)
-- use pacifcandes503
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
Set @Ins_row=@Ins_row+1 ------计数器,每插入一条,加1
-----------------纪录更新id值---------------
set @str='Update PAOS_TEMP.dbo.update_2 Set minid='+char(39)+rtrim(@id)+char(39)+' where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
end
close R_x
DEALLOCATE R_x
-----------------------------校验数据量------------------
print'----------------------'
print 'MAXID'+rtrim(@ST)
print 'minid='+rtrim(@minid)
print 'ins_row='+rtrim(@ins_row)
print'-----------------------'
---------------------------清理已同步数据----------------
--USE PAOS_TEMP
set @str='Delete From PAOS_TEMP.dbo.PAOS_trim_regs where state=1' -----<<须更改表名
exec(@str)
---写更新时间
set @str='Update PAOS_TEMP.dbo.update_2 Set end_time=CONVERT(varchar,getdate(),120) where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
--写日志
set @str='insert into PAOS_TEMP.dbo.ins_log_2 (Minid,Maxid,OP_Count,OP_Tab_Name,OP_User,OP_shift,OP_OPtion) values ('+char(39)+ltrim(@minid)+char(39)+','+char(39)+ltrim(@ST)+char(39)+','+char(39)+ltrim(@ins_row)+char(39)+','+char(39)+rtrim(@P_name)+char(39)+','+char(39)+rtrim(@P_user)+char(39)+','+char(39)+rtrim(@oP_shift)+char(39)+','+char(39)+rtrim('Update')+char(39)+')'
exec(@str)
return @Ins_row
--end
#6
自己到查询分析器里调试吧
#7
#8
我又修改了一下存储过程,如下,
PB代码如下:
integer ls_reture
string ls_user
string ld_date
ld_date='20101216'
ls_user='chris'
DECLARE p1 PROCEDURE FOR dbo.Update_TR_1
@P_date = :ld_date, @P_user=:ls_user ,@ins_row=:ls_reture output,
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
messagebox("OK",ls_reture)
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
为什么结果一直是0呢
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
create PROCEDURE [dbo].[Update_TR_1]
@P_date varchar(10),
@P_user varchar(10),
@Ins_row int output
AS
SET NOCOUNT ON;
--BEGIN
--硬代码用于测试
--declare @P_date datetime ,@P_user nvarchar(10) ,@P_shift nvarchar(5)
--set @P_date=CONVERT(varchar,'20101213',120)
--set @P_user='chris'
--set @P_shift='15'
declare @ST int,@id int,@prperiod int,@shift int,@prday datetime,@employee int,@material int,@weight real,@regtime datetime,@rtype smallint,
@maxid int,@count int,@check_count int,@check_maxid int,@maxupdate int,
@minid int,@OP_shift nchar(5),@P_name nchar(20)
Set @Ins_row=0
set @P_name='PAOS_trim_regs'
---写状态到updat表中 state=true
-----------------------------取出上一次成功同步的数据------------
declare starde cursor-------------------------------------定义游标“starde”
for Select updateid,minid,op_shift From PAOS_TEMP.dbo.update_2 where updatename='PAOS_trim_regs'---
open starde
fetch next from starde into @ST,@minid,@OP_shift
close starde
DEALLOCATE starde
-----取出最新数据----
declare R_x cursor
for select id,prperiod,shift,prday,employee,material,weight,regtime,rtype from pacifcandes503.dbo.trim_regs where id >@minid and id<=@ST and prday=@P_date Order by id
open R_x
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
declare @str varchar(300)
while @@fetch_status=0
begin
set @str='Insert into PAOS_TEMP.dbo.PAOS_trim_regs (id,prperiod,shift,prday,employee,material,weight,regtime,rtype,state) Values('+rtrim(@id)+','+rtrim(@prperiod)+','+char(39)+rtrim(@shift)+char(39)+','+char(39)+rtrim(@prday)+char(39)+','+char(39)+ltrim(@employee)+char(39)+','+rtrim(@material)+','+rtrim(@weight)+','+char(39)+rtrim(@regtime)+char(39)+','+rtrim(@rtype)+',0)'
exec(@str)
-- use pacifcandes503
fetch next from R_x into @id,@prperiod,@shift,@prday,@employee,@material,@weight,@regtime,@rtype
Set @Ins_row=@Ins_row+1 ------计数器,每插入一条,加1
-----------------纪录更新id值---------------
set @str='Update PAOS_TEMP.dbo.update_2 Set minid='+char(39)+rtrim(@id)+char(39)+' where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
end
close R_x
DEALLOCATE R_x
-----------------------------校验数据量------------------
print'----------------------'
print 'MAXID'+rtrim(@ST)
print 'minid='+rtrim(@minid)
print 'ins_row='+rtrim(@ins_row)
print'-----------------------'
---------------------------清理已同步数据----------------
--USE PAOS_TEMP
set @str='Delete From PAOS_TEMP.dbo.PAOS_trim_regs where state=1' -----<<须更改表名
exec(@str)
---写更新时间
set @str='Update PAOS_TEMP.dbo.update_2 Set end_time=CONVERT(varchar,getdate(),120) where updatename='+char(39)+'PAOS_trim_regs'+char(39)
exec(@str)
--写日志
set @str='insert into PAOS_TEMP.dbo.ins_log_2 (Minid,Maxid,OP_Count,OP_Tab_Name,OP_User,OP_shift,OP_OPtion) values ('+char(39)+ltrim(@minid)+char(39)+','+char(39)+ltrim(@ST)+char(39)+','+char(39)+ltrim(@ins_row)+char(39)+','+char(39)+rtrim(@P_name)+char(39)+','+char(39)+rtrim(@P_user)+char(39)+','+char(39)+rtrim(@oP_shift)+char(39)+','+char(39)+rtrim('Update')+char(39)+')'
exec(@str)
return
PB代码如下:
integer ls_reture
string ls_user
string ld_date
ld_date='20101216'
ls_user='chris'
DECLARE p1 PROCEDURE FOR dbo.Update_TR_1
@P_date = :ld_date, @P_user=:ls_user ,@ins_row=:ls_reture output,
execute p1;
if sqlca.sqlcode=0 then
fetch p1 into :ls_reture ;
messagebox("OK",ls_reture)
else
rollback using sqlca;
messagebox("系统信息","执行错误!")
end if
close p1;
为什么结果一直是0呢
#9
#10
多fetch几次试试
fetch p1 into :ls_reture ;此句可能获取的是return的默认值0
fetch p1 into :ls_reture ;此句可能获取output参数
fetch p1 into :ls_reture ;此句可能获取的是return的默认值0
fetch p1 into :ls_reture ;此句可能获取output参数
#11
不行,取不到返回值,
#12
设置sqlca.AutoCommit = true试试