注册 登录
编程论坛 Delphi论坛

如何实现一次查询整个数据库的表

aaron52088 发布于 2007-02-20 15:55, 1509 次点击

我想在一个edit中输入一个ID号,然后数据库中有3个表(表名为表一,表二,表三),
在delphi怎样用查询语句可以实现在3个表中查询呢

大家帮忙看看的,谢谢先

10 回复
#2
xu20002007-02-20 20:12
没明白楼主的意思。
#3
sgliuxiu2007-02-21 01:25
你的意思可能是这三个表里面都有都可能有这个id或者是一定有这个id?
这好办啊, 用adoquery
#4
aaron520882007-02-24 21:08
哦,我的意思是说我一个数据库中有3个表(长期客户管理表,临时客户管理表,永久客户管理表),每个表的主键分别为cqkhid,lskhid,yjkhid。
我想在一个edit中,输入一个ID号,然后可以用adoquery实现查询3个表的。
主要是写到adoquery1.sql.add('select * from ...');这里不会写了,
帮忙下,谢谢先
#5
nongen2007-02-25 10:45
UNION
#6
aaron520882007-02-28 10:46

楼上的可以写一点具体的语句吗?
谢谢了

#7
nongen2007-02-28 12:01
database.temp.SQL.Append('(SELECT dbo.csale.code AS 单据编号, dbo.csale.billdate AS 开单日期, '+
'dbo.client.shortname AS 往来单位, dbo.operator.opname AS 操作员, '+
'dbo.shop.name AS 部门, dbo.employ.name AS 业务员, dbo.csale.totalamt AS 金额, '+
'dbo.csale.totalamt AS 已收款, dbo.credtype.name AS 收款方式, ''现款销售单'' AS 单据类型 '+
'FROM dbo.shop INNER JOIN '+
'dbo.csale INNER JOIN '+
'dbo.operator ON dbo.csale.opid = dbo.operator.opid INNER JOIN '+
'dbo.client ON dbo.csale.clientid = dbo.client.clientid ON '+
'dbo.shop.shopid = dbo.csale.shopid INNER JOIN '+
'dbo.employ ON dbo.csale.exemanid = dbo.employ.empid INNER JOIN '+
'dbo.credence ON dbo.csale.credid = dbo.credence.credid INNER JOIN '+
'dbo.credtype ON dbo.credence.credtypeid = dbo.credtype.id '+
'WHERE (csale.totalamt<>csale.totalamt)and (dbo.employ.name='''+man.Text+''') and (dbo.csale.billdate <= '''+datetostr(date-d3.Value)+''') '+
'UNION ALL '+
'SELECT TOP 100 PERCENT dbo.invoice.code AS 单据编号, '+
'dbo.invoice.billdate AS 开单日期, dbo.client.shortname AS 往来单位, '+
'dbo.operator.opname AS 操作员, dbo.shop.name AS 部门, '+
'dbo.employ.name AS 业务员, dbo.invoice.totalamt AS 金额, '+
'dbo.invoice.totalrcvd AS 已收款, dbo.credtype.name AS 收款方式, ''销售开单'' AS 单据类型 '+
'FROM dbo.invoice INNER JOIN '+
'dbo.shop ON dbo.invoice.shopid = dbo.shop.shopid INNER JOIN '+
'dbo.operator ON dbo.invoice.opid = dbo.operator.opid INNER JOIN '+
'dbo.employ ON dbo.invoice.exemanid = dbo.employ.empid INNER JOIN '+
'dbo.client ON dbo.invoice.clientid = dbo.client.clientid INNER JOIN '+
'dbo.credence ON dbo.invoice.credid = dbo.credence.credid INNER JOIN '+
'dbo.credtype ON dbo.credence.credtypeid = dbo.credtype.id WHERE (invoice.totalamt<>invoice.totalrcvd) and (dbo.employ.name='''+man.Text+''') and dbo.invoice.billdate < '''+datetostr(date-d3.Value)+''' ) '+
'UNION ALL '+
'SELECT TOP 100 PERCENT dbo.sreturn.code AS 单据编号, '+
'dbo.sreturn.billdate AS 开单日期, dbo.client.shortname AS 往来单位, '+
'dbo.operator.opname AS 操作员, dbo.shop.name AS 部门, '+
'dbo.employ.name AS 业务员, dbo.sreturn.totalamt AS 金额, '+
'dbo.sreturn.totalrcvd AS 已收款, dbo.credtype.name AS 收款方式, ''销售退货单'' AS 单据类型 '+
'FROM dbo.sreturn INNER JOIN '+
'dbo.client ON dbo.sreturn.clientid = dbo.client.clientid INNER JOIN '+
'dbo.operator ON dbo.sreturn.opid = dbo.operator.opid INNER JOIN '+
'dbo.employ ON dbo.sreturn.exemanid = dbo.employ.empid INNER JOIN '+
'dbo.shop ON dbo.sreturn.shopid = dbo.shop.shopid INNER JOIN '+
'dbo.credence ON dbo.sreturn.credid = dbo.credence.credid INNER JOIN '+
'dbo.credtype ON dbo.credence.credtypeid = dbo.credtype.id WHERE (sreturn.totalamt<>sreturn.totalrcvd)and (dbo.employ.name='''+man.Text+''') and(dbo.sreturn.billdate < '''+datetostr(date-d3.Value)+''') '+
'order by 开单日期')
#8
aaron520882007-03-01 15:23
已收款 单据编号 开单日期

这些都是表的别名吗?
这段程序写在什么地方呢?告诉我下,很谢谢你了
#9
初学Delphi2007-03-01 16:25
select name from sysobjects where type='u'
#10
初学Delphi2007-03-01 16:26
不好意思 看错楼主的意思了...
#11
nongen2007-03-03 13:11
回复:(aaron52088)已收款 单据编号 开单日期这些...
以下是引用aaron52088在2007-3-1 15:23:41的发言:
已收款 单据编号 开单日期

这些都是表的别名吗?
这段程序写在什么地方呢?告诉我下,很谢谢你了

这里的是列名。

1