一堆sql语句,两个输入性变量jsource和jcurrent
不知道如何让sql server执行
一般是用ODBC
    如query1用法
但是我用ado
所以需要ado的一个组件,另在数据库中建好stored procedure  //思路对吧?
  现建好一个,命名为get_id
CREATE PROCEDURE get_id
(@jsource char(4),
 @jcurrent char(4)
) AS
begin
 delete from table_temp
DECLARE @f char(4) 
DECLARE @f1 char(4)
DECLARE @c char(4)
set @f =@jsource
SET @f1 =@jcurrent
WHILE EXISTS (SELECT * FROM table_outport
         WHERE junctionbox_ID = @f1)
 BEGIN
        SELECT @c = cable_ID
        FROM table_outport
        WHERE junctionbox_ID = @f1
        INSERT table_temp VALUES (@c)
        SELECT @f1 = junctionbox_ID
        FROM table_inport
        WHERE cable_ID = @c
        IF @f = @f1  
        BREAK 
        ELSE
        CONTINUE
  END
end    (这个试过,成功)   运行sql语句
   adoquery2.sql.add('exec get_id :jsource :jcurrent');
   adoquery2.parameters.parambyname('jsource').value:='j1';
   adoquery2.parameters.parambyname('jcurrent').value:='j5';
   adoquery2.execsql;
运行时提示error
"adoquery2:parameter'jsource'not found"
问题是:是否adoquery2.sql.add的语句错了,请教
另SET @f1 =@jcurrent和select @f1 =@jcurrent一样吗?

解决方案 »

  1.   

    1、
    try:
       adoquery2.sql.add('exec get_id ''j1'',''j5'' ');
       adoquery2.execsql;2、一样的,但select 可以:select @f1 =@jcurrent,@f2=34534,@f3='sdfasf'

    set 只能赋一个值
      

  2.   

    adoquery2.sql.add('exec get_id :jsource, :jcurrent');两个参数之间少个逗号
      

  3.   

    adoquery2.sql.add('exec get_id :jsource :jcurrent');
       adoquery2.parameters.parambyname('jsource').Asstring:=QuoteStr('j1');
       adoquery2.parameters.parambyname('jcurrent').Asstring:=QuoteStr('j5');
       adoquery2.execsql;或者直接:
    adoquery2.sql.add('exec get_id ''j1'',''j5''');
       adoquery2.execsql;
    运行时提示error
      

  4.   

    我把大力的方法改了一下,抛开adoquery2.parameters.parambyname('jsource').value:='j1';
    用adoquery2.sql.text:='exec get_id 'edit1.text'';
    可以用了