delphi2006,有两个adoquery控件,动态添加sql如下:
ADOQuery_Goods.Close;
ADOQuery_Goods.SQL.Clear;
ADOQuery_Goods.SQL.Add('select * from goods where '+GoodsFieldName+' like :name');
ADOQuery_Goods.Parameters.ParamValues['name']:='%'+LabeledEdit_Locket.Text+'%';
ADOQuery_Price.Close;
ADOQuery_Price.SQL.Clear;
ADOQuery_Price.SQL.Add('select * from price where spbh in (select dm from goods where '
+GoodsFieldName+' like :name )');
ADOQuery_Price.Parameters.ParamValues['name']:='%'+LabeledEdit_Locket.Text+'%';goods是商品表,price是对应的价格表,按说执行后,两个查询出的结果条数应该是一样的.但运行时结果却不一样.用sqlserver的事件探查器跟踪了一下.发现
ADOQuery_Goods实际执行的是:exec sp_executesql N'select * from goods where mc like @P1
', N'@P1 varchar(50)', '%盖%'
ADOQuery_Price实际执行的是:exec sp_executesql N'select * from price where spbh in (select dm from goods where mc like @P1 )
', N'@P1 varchar(3)', '%盖'搞不明白,为什么ADOQuery_Price执行的时候,就成了@P1 varchar(3)了?
另外还想问一下,我这样写代码是否合理,有没有更好的写法.希望不吝赐教,谢谢!
ADOQuery_Goods.Close;
ADOQuery_Goods.SQL.Clear;
ADOQuery_Goods.SQL.Add('select * from goods where '+GoodsFieldName+' like :name');
ADOQuery_Goods.Parameters.ParamValues['name']:='%'+LabeledEdit_Locket.Text+'%';
ADOQuery_Price.Close;
ADOQuery_Price.SQL.Clear;
ADOQuery_Price.SQL.Add('select * from price where spbh in (select dm from goods where '
+GoodsFieldName+' like :name )');
ADOQuery_Price.Parameters.ParamValues['name']:='%'+LabeledEdit_Locket.Text+'%';goods是商品表,price是对应的价格表,按说执行后,两个查询出的结果条数应该是一样的.但运行时结果却不一样.用sqlserver的事件探查器跟踪了一下.发现
ADOQuery_Goods实际执行的是:exec sp_executesql N'select * from goods where mc like @P1
', N'@P1 varchar(50)', '%盖%'
ADOQuery_Price实际执行的是:exec sp_executesql N'select * from price where spbh in (select dm from goods where mc like @P1 )
', N'@P1 varchar(3)', '%盖'搞不明白,为什么ADOQuery_Price执行的时候,就成了@P1 varchar(3)了?
另外还想问一下,我这样写代码是否合理,有没有更好的写法.希望不吝赐教,谢谢!
那个长度的问题,你看下是不是adoquery的Parameters的Size长度设置
ADOQuery_Price.Close;
ADOQuery_Price.SQL.Text := 'select * from price where spbh in( '
+ 'select dm from goods where ' + GoodsFieldName + ' like ''%' + trim(LabeledEdit_Locket.Text) + '%'')';
ADOQuery_Price.Open;