这是什么问题啊 无语
我写了一个存储过程
建了一个虚拟表
CREATE TABLE #ProductsToPrepare
(
[ProductId] int NOT NULL,
[Quantity] int,
[orderid] int
)
SET @SQL = 'INSERT INTO #ProductsToPrepare (ProductId,Quantity,orderid) select ss.productid,Sum(ss.Quantity)from ( '
SET @SQL = @SQL + ' SELECT e.ExchangeId as productid,e.quantity*hh.quantity as quantity,hh.orderid FROM huanaigu.productexchange e '
SET @SQL = @SQL + ' left join (select productid,sum(quantity),orderid as quantity from huanaigu.orderproduct where orderid IN (SELECT OrderId FROM huanaigu.Orders WHERE OrderStatusId=2) group by productid ) hh on e.productid=hh.productid '
SET @SQL = @SQL + 'where e.productid in(select productid from huanaigu.orderproduct where orderid in(SELECT OrderId FROM huanaigu.Orders WHERE OrderStatusId=2) group by productid) ) ss group by ss.productid'
exec sp_executesql @SQL
可是调试的时候老是报错误、
错误如下
服务器: 消息 8157,级别 16,状态 1,行 1
[Microsoft][ODBC SQL Server Driver][SQL Server]包含 UNION 运算符的查询表达式中的所有查询都必须在选择列表中包含同样数目的表达式。
获取调用堆栈失败!
大家帮忙看看是什么问题啊