JohnDTampaBay
Programmer
I have the following SELECT that uses a derived, pivot table. I am pivoting a normalized table on the fly.
When run, I am receiving the following error message. What does this mean? How can a table have more columns than * (all columns)?
Server: Msg 8158, Level 16, State 1, Line 2
'aoi' has more columns than were specified in the column list.
----------------------------------------------------------
----------------------------------------------------------
--Angel![[rainbow] [rainbow] [rainbow]](/data/assets/smilies/rainbow.gif)
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
When run, I am receiving the following error message. What does this mean? How can a table have more columns than * (all columns)?
Server: Msg 8158, Level 16, State 1, Line 2
'aoi' has more columns than were specified in the column list.
----------------------------------------------------------
Code:
Select o.CustID, c.FirstName, c.LastName, c.Suffix,
c.Title, c.CoName, a.Address1, a.City, a.State,
a.PostalCode, oi.ProdCode, o.OrderDate, oi.OrderID,
oi.OrderItemID, aoi.*
From Orders o With (NoLock)
Join OrderItems oi (NoLock)
On oi.OrderID = o.OrderId
Join Customers c (NoLock)
On c.CustId = o.CustId
Join (SELECT OrderItemID,
MIN(CASE KeyName WHEN 'ZIP' THEN KeyValue
ELSE NULL END) AS [ZIP],
MIN(CASE KeyName WHEN 'COCODE' THEN KeyValue
ELSE NULL END) AS [COCODE],
MIN(CASE KeyName WHEN 'AGE' THEN KeyValue
ELSE NULL END) AS [AGE],
MIN(CASE KeyName WHEN 'STATE' THEN KeyValue
ELSE NULL END) AS [STATE],
MIN(CASE KeyName WHEN 'GENDER' THEN KeyValue
ELSE NULL END) AS [GENDER],
MIN(CASE KeyName WHEN 'GRADE' THEN KeyValue
ELSE NULL END) AS [GRADE]
FROM AdditionalOrderInfo (NOLOCK)
GROUP BY OrderItemID) aoi (NoLock)
On aoi.OrderItemId = oi.OrderItemId
Join Address a (NoLock)
On a.AddressID = oi.ShipToAddress
Where o.OrderDate Between '2/26/2003' And '03/05/2003'
And (oi.status = '01' or oi.status = '03')
And oi.BalanceDue <= 0
Order By o.OrderDate, o.CustID, oi.OrderItemID
--Angel
![[rainbow] [rainbow] [rainbow]](/data/assets/smilies/rainbow.gif)
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.