|
楼主 |
发表于 2010-4-18 12:18
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
回复 5楼 livewire 的帖子
去除小小的纰漏后(第三行开始,每个新增字段后要加一个“AS 客户“),发现提示“在联合查询中所选定的两个数据表或查询的列数不匹配”,
但很奇怪,我的每个SHEET都是统一由第一个SHEET中复制过去再删除除表头之外的其他内容,怎么会提示列数不匹配呢,而且,我已经再一次用CTRL+END来看表的结尾,都是到我最后一行,最后一行数据处,应该说不用有这种现象。
提示列数不匹配:
SELECT 客户,ITEM,PRICE,QTY,WEEKLY FROM (
SELECT 'EO' AS 客户, * from [EO$] UNION ALL
SELECT 'IF' AS 客户, * from [IFi$] UNION ALL
SELECT 'KG' AS 客户, * from [HK_KG$] UNION ALL
SELECT 'KG' AS 客户, * from [USA_KG$] UNION ALL
SELECT 'JP' AS 客户, * from [JP$] UNION ALL
SELECT 'SL' AS 客户, * from [SL$] UNION ALL
SELECT 'TM' AS 客户, * from [TM$] UNION ALL
SELECT 'WW' AS 客户, * from [WW$] UNION ALL
SELECT 'TY' AS 客户, * from [TY$] UNION ALL
SELECT 'WO' AS 客户, * from [WO$] UNION ALL
SELECT 'KA' AS 客户, * from [KA$] UNION ALL
SELECT 'TI' AS 客户, * from [TI$] UNION ALL
SELECT 'NK' AS 客户, * from [NK$] UNION ALL
SELECT 'MT' AS 客户, * from [MT$] UNION ALL
SELECT 'WD' AS 客户, * from [WD$])
WHERE WEEKLY LIKE 'WK__'
另外,因为所有的数据源都在同一个工作簿中,而且已经在连接中指定了源,能否在后面的语句中不用再反映呢?试试看后,是行的,但新问题又来了,QTY求和时都是0,原来它将QTY数据当成了文本形式。也许是电脑的原因吧。
最后的问题还是没有解决,再多加一个SHEET上去的话,就不行了,提示超出系统资源:(已经删除最后一行的SHEET,可以用,但QTY求和变文本了,求出来是0。)
select * from (SELECT "EO" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [EO$] UNION ALL
SELECT "IFI" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [IFI$] UNION ALL
SELECT "KG" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [HK_KG$] UNION ALL
SELECT "KG" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [USA_KG$] UNION ALL
SELECT "JP" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [JP$] UNION ALL
SELECT "SL" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [SL$] UNION ALL
SELECT "TM" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [TM$] UNION ALL
SELECT "WW" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [WW$] UNION ALL
SELECT "TY" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [TY$] UNION ALL
SELECT "WO" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [WO$] UNION ALL
SELECT "KA" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [KA$] UNION ALL
SELECT "TI" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [TI$] UNION ALL
SELECT "NK" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [NK$] UNION ALL
SELECT "MT" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [MT$] UNION ALL
SELECT "WD" AS 客户,ITEM,PRICE,QTY,WEEKLY FROM [WD$]) WHERE WEEKLY LIKE 'WK__‘
[ 本帖最后由 fenghcl 于 2010-4-18 15:58 编辑 ] |
-
连接源路径已经表达,应该可以省去。
|