求救where ... in ....如何写??(0分)

  • 主题发起人 主题发起人 esnow
  • 开始时间 开始时间
E

esnow

Unregistered / Unconfirmed
GUEST, unregistred user!
with ADOQuery_Sys do
begin
Close;
SQL.Clear;
SQL.Add(Format('Select RyDm from v_Ry_Bm_Jg where bmdm = ''%s''', [P_bmdm]));
// SQL.Add(Format('and KsDm = ''%s'' order by RyDm', [P_BmDm]));

//Open;
//if (ADOQuery_Sys.RecordCount > 0) then
// for I := 1 to ADOQuery_Sys.RecordCount do
with ADOQuery_tmp do
begin
Close;
SQL.Clear ;
SQL.Add (Format('Select rydm,xm from Rs_Zgda_Jbxx where ksdm = ''%s''', [P_bmdm]));
SQL.Add (Format(' and RyDm in ''%s''', [ADOQuery_sys.ExecSQL]));
sql.SaveToFile ('c:/test.sql');
// open;
// if (ADOQuery_tmp.RecordCount > 0) then
//MessageDlg('功能〖'+p_bmdm+'〗未定义!', mtInformation, [mbOk], 0);
// FindFastCode(ADOQuery_tmp, Edit_RyDm, mPosition, 200, 0);
end;
end;
end;
我想搜索一些记录是否在另一个搜索的结果集中。。。看下我的代码有什么问题吗?
 
哦。拜托了呀。急呀。。
 
select * from table1 where sj like '%abc%'

列出SJ字段包含字符串abc的数据
 
select * from table1 where sj like '%abc%'???
我的意思是
ADOQuery_Sys 中
SQL.Add(Format('Select RyDm from v_Ry_Bm_Jg where bmdm = ''%s''', [P_bmdm]));
这里有若干记录
但是在
SQL.Add (Format('Select rydm,xm from Rs_Zgda_Jbxx where ksdm = ''%s''', [P_bmdm]));
也有记录但是有一小部分记录与ADOQuery_Sys 里面记录相同,所以不想显示了。只显示
ADOQuery_tmp在ADOQuery_Sys 中没有的记录。。。
记录集里面
 
类似与
USE pubs
SELECT pub_name
FROM publishers
WHERE pub_id IN
(SELECT pub_id
FROM titles
WHERE type = 'business')

下面是结果集:

pub_name
----------------------------------------
Algodata Infosystems
New Moon Books

(2 row(s) affected)

样式的。但是我的
SQL.Add (Format(' and RyDm in ''%s''', [ADOQuery_sys.ExecSQL]));
有错误。提示的好象是%s格式不对。。
 
不知所云 ,太乱
 
SQL.Add (Format(' and RyDm in ''%s''', [ADOQuery_sys.ExecSQL]));
改成
SQL.Add (Format(' and RyDm in (%s)', [ADOQuery_sys.sql.text]));
 
只要把
SQL.Add (Format(' and RyDm in ''%s''', [ADOQuery_sys.ExecSQL]));
改为
SQL.Add (Format(' and RyDm in (%s)', [ADOQuery_sys.ExecSQL]));
因为 in 后的子查询应该在()里,且不因带'',不然会变成类似:
select x from a where y in 'select o from b'
 
我把运行的结果写到文件中是
Select rydm,xm from Rs_Zgda_Jbxx where ksdm = '01200101'
and RyDm in (Select RyDm from v_Ry_Bm_Info where bmdm = '01200101'
)
这是处理一个数据库呀。我的v_Ry_Bm_Info 是另外一个数据库的表
 
ADOQuery_Sys.v_Ry_Bm_Info
我可以写类似与
select rydm from 数据库名.v_ry_bm_info where....吗?
 
是SQL SERVER搞定了。是这样的。
with ADOQuery_tmp do
begin
Close;
SQL.Clear;
SQL.Add (Format('Select rydm from wsrscwdb.dbo.Rs_Zgda_Jbxx where ksdm = ''%s''', [Form120404.Edit_Ks.hint]));
with ADOQuery_sys do
begin
Close;
SQL.Clear ;
SQL.Add (Format('Select rydm,xm from v_ry_bm_jg where bmdm = ''%s''', [Form120404.Edit_Ks.hint]));
SQL.Add (Format(' and RyDm not in (%s)', [ADOQuery_tmp.sql.text]));
// sql.SaveToFile ('c:/test.sql');
open;
if (ADOQuery_sys.RecordCount > 0) then
FindFastCode(ADOQuery_sys, Edit_RyDm, mPosition, 200, 0);
end;
end;
end;
需要加的是这部分
SQL.Add (Format('Select rydm from wsrscwdb.dbo.Rs_Zgda_Jbxx where ksdm = ''%s''', [Form120404.Edit_Ks.hint]));
哈。谢谢。。。。。 QuickSilver
 
后退
顶部