0

I'm completely new to the SQL Server portion of databases. I've created a split Access database that functions well.

As a test I upsized the tables to SQL server. For the most part everything went smoothly; however, two of my queries are no longer working. They are both fairly complex union queries. I believe the union is the culprit to my issues.

With the first one I have two queries using union all. They work individually, but when I use the union query I receive the error "object invalid or no longer set".

With the second one I have 3 queries with union all. These are simpler than the first case. This time I receive the error "The expression is typed incorrectly, or it is too complex to be evaluated."

Is there something specific about union queries with tables on SQL server? Any help or advice is appreciated.

SELECT scrap.coilnum, Sum(scrap.lnff) AS sumoflnff, scrap.code, scrap.location
FROM scrap
WHERE scrap.day>=[Forms]![coilparameters]![Text0] And scrap.day<=[Forms]![coilparameters]![Text2] and scrap.productionline=[Forms]![coilparameters]![combo4] and scrap.coilnum<>0
GROUP BY scrap.coilnum, scrap.code, scrap.location;
union all
SELECT sawscrap.tcoilnum, Sum(sawscrap.length) AS sumoflnff, sawscrap.code, sawscrap.location
FROM sawscrap
WHERE sawscrap.day>=[Forms]![coilparameters]![text0] And sawscrap.day<=[Forms]![coilparameters]![text2] and sawscrap.productionline=[Forms]![coilparameters]![combo4] and sawscrap.tcoilnum is not null and sawscrap.tcoilnum<>0
GROUP BY sawscrap.tcoilnum, sawscrap.code, sawscrap.location;
UNION ALL
SELECT sawscrap.bcoilnum, Sum(sawscrap.length) AS sumoflnff, sawScrap.code, sawscrap.location
FROM sawscrap
WHERE sawscrap.day>=[Forms]![coilparameters]![text0] And sawscrap.day<=[Forms]![coilparameters]![text2] and sawscrap.productionline=[Forms]![coilparameters]![combo4] and sawscrap.bcoilnum is not null and sawscrap.bcoilnum<>0
GROUP BY sawscrap.bcoilnum, sawscrap.code, sawscrap.location;

There is the second one.

4

1 回答 1

0

Access 查询中此类错误的常见原因是每列与其他语句中相同位置的列UNION之间的数据类型不匹配。SELECTSELECT

在您的情况下,scrap.coilnum,sawscrap.tcoilnum和的数据类型sawscrap.bcoilnum是否相同?其他列呢?如果不是,您可能需要使用转换函数(例如CStrCLng)使它们都具有相同的类型。

看看这个以获取更多信息。

于 2013-09-23T22:23:18.280 回答