如何调用SQL存储过程到delphi
ALTERPROCEDURE[sp_new2]@bhvarchar(50),@mcvarchar(50)ASdeclare@sqlvarchar(7000)select@...
ALTER PROCEDURE [sp_new2] @bh varchar(50),@mc varchar(50) AS
declare @sql varchar(7000)
select @sql= 'select * from (select bh,mc,gg,dw,sum(rksl-cksl) as sl, sum((rksl-cksl)*dj) as hj from
(select isnull(bh,'''') as bh,mc,gg,dw,isnull(sl,0) as rksl,0 as cksl,dj from rk where isnull(sl,0)<>0 '
if @bh <> ''
select @sql= @sql+' and bh like ''' + @bh + '%'''
if @mc <> ''
select @sql= @sql+' and mc like ''' + @mc + '%'''
select @sql= @sql+' union all select isnull(bh,'''') as bh,mc,gg,dw,0 as rksl,isnull(sl,0) as cksl,dj from ck where isnull(sl,0)<>0 '
if @bh <> ''
select @sql= @sql+' and bh like ''' + @bh + '%'''
if @mc <> ''
select @sql= @sql+' and mc like ''' + @mc + '%'''
select @sql= @sql+' ) b group by bh,mc,gg,dw) DERIVEDTBL where sl<>0 '
exec (@sql)
这是我的后台过程,我前台想调用,
@bh trim(edit1.text) @mc trim(edit2.text)
kcAdo.Close;
kcAdo.sql.Clear;
kcado.sql.Add('sp_new2'+);
kcAdo.Open;
sp_new2 后面的我不知道怎么写格式了是把我那2个edit.text.填进去.但符号我不知道怎么加.
希望有人帮我写一下,谢谢 展开
declare @sql varchar(7000)
select @sql= 'select * from (select bh,mc,gg,dw,sum(rksl-cksl) as sl, sum((rksl-cksl)*dj) as hj from
(select isnull(bh,'''') as bh,mc,gg,dw,isnull(sl,0) as rksl,0 as cksl,dj from rk where isnull(sl,0)<>0 '
if @bh <> ''
select @sql= @sql+' and bh like ''' + @bh + '%'''
if @mc <> ''
select @sql= @sql+' and mc like ''' + @mc + '%'''
select @sql= @sql+' union all select isnull(bh,'''') as bh,mc,gg,dw,0 as rksl,isnull(sl,0) as cksl,dj from ck where isnull(sl,0)<>0 '
if @bh <> ''
select @sql= @sql+' and bh like ''' + @bh + '%'''
if @mc <> ''
select @sql= @sql+' and mc like ''' + @mc + '%'''
select @sql= @sql+' ) b group by bh,mc,gg,dw) DERIVEDTBL where sl<>0 '
exec (@sql)
这是我的后台过程,我前台想调用,
@bh trim(edit1.text) @mc trim(edit2.text)
kcAdo.Close;
kcAdo.sql.Clear;
kcado.sql.Add('sp_new2'+);
kcAdo.Open;
sp_new2 后面的我不知道怎么写格式了是把我那2个edit.text.填进去.但符号我不知道怎么加.
希望有人帮我写一下,谢谢 展开
1个回答
展开全部
delphi调用存储过程,有它的专用控件,即ADOStordProc和BDEStordProc.
调用方式类似:
delphi 调用过程:(添加的TStoredProc控件命名为SP1)
SP1.Close;
SP1.unprepare;
SP1.StoredProcName := 'DEV_OUTPREP';
SP1.Prepare;
SP1.ParamByName('P_DEV').ASString := Trim(edit1.Text);
SP1.ParamByName('P_ISN').ASstring := Trim(edit2.Text);
sp1.ExecProc;
其中的P_DEV,P_ISN为需要传入存储过程的参数,就是你的2个edit.text需要传入的值.
详细可以参看我的空间笔:
http://hi.baidu.com/yueyun889/blog/item/2df075599992442a2934f0ff.html
调用方式类似:
delphi 调用过程:(添加的TStoredProc控件命名为SP1)
SP1.Close;
SP1.unprepare;
SP1.StoredProcName := 'DEV_OUTPREP';
SP1.Prepare;
SP1.ParamByName('P_DEV').ASString := Trim(edit1.Text);
SP1.ParamByName('P_ISN').ASstring := Trim(edit2.Text);
sp1.ExecProc;
其中的P_DEV,P_ISN为需要传入存储过程的参数,就是你的2个edit.text需要传入的值.
详细可以参看我的空间笔:
http://hi.baidu.com/yueyun889/blog/item/2df075599992442a2934f0ff.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询