Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

How to resolve the error: Microsoft SQL DMO (ODBC SQLSTATE 42S22) Error 207 Invalid Column Name ?

Do you know how I can resolve the error in the stored procedure that follows:
 
Microsoft SQL DMO (ODBC SQLSTATE 42S22) Error 207
Invalid column name 'CustomerNumber'
Invalid column name 'OfficeNumber'

I am able to narrow the error down to the following ON statement:

ON       C.CustomerNumber = P.CustomerNumber AND
           C.OfficeNumber      = P.OfficeNumber

-------------------------------------------------------------------------------

CREATE PROCEDURE procDetailBranches
@Branch nvarchar (4)
As

Set Nocount ON

Declare @FromDateA datetime,
             @ToDateA datetime,
             @FromDateB datetime,
             @ToDateB datetime,
             @tempdate datetime

--  get our base datetime.. for use throughout procedure. avoids problems when running
-- close to midnight...
Set @tempdate=getdate()

Set @ToDateA = CAST(CONVERT(char(8), @tempdate, 112) As datetime) - DAY(@tempdate) + 1
Set @FromDateA = DATEADD(Month, - 5, @ToDateA)

Set @ToDateB = DateAdd(Month, -6,CAST(CONVERT(char(8), @tempdate, 112) As datetime) - DAY(@tempdate) + 1)
Set @FromDateB = DATEADD(Month, -5, @ToDateB)

Select Case gDateRange
            When 0 then DateRange
            Else ' '
            End as DateRange
          ,Case gCustomerNumber
            When 0 then BCH_Customer
            Else Space(10)
            End as [BCH_CustomerNumber]
          ,Case gAcctValue
            When 0 then Right(space(13) + Convert(varchar(13),[Acct Value]),13)
            Else Space(13)
            End as [Acct Value]
          ,Case gAcctValue
            When 0 then Right(Space(10) + Convert(varchar(10),NumofValues),10)
            Else space(10)
            End as NumofValues
          ,Case When gdateRange=0 and gCustomerNumber=0 and gAcctValue=0 Then Space(13)
            Else Right(space(13) + Convert(varchar(13),TotAcctValue),13)
            End As TotalAcctValue
From (  
SELECT Top 100 Percent
       DateRange
      ,C.BCH_Customer
      ,[Acct Value]
      ,Count(*) As NumofValues
      ,Sum([Acct Value]) As TotAcctValue
      ,Grouping([Acct Value]) as gAcctValue
      ,Grouping(C.BCH_Customer) as gCustomerNumber
      ,Grouping(DateRange) as gDateRange
  FROM (Select y.*
              ,CASE WHEN LostDate BETWEEN @FromDateA AND @ToDateA THEN 'LESS THAN 06 MONTHS OLD'
                         WHEN LostDate BETWEEN @FromDateB AND @ToDateB THEN '06 MONTHS TO 12 MONTHS OLD'
                         END AS DateRange
  FROM(Select x.*
              ,CAST(CONVERT(char(8), x.DateLost, 112) As DATETIME) As LostDate
              ,Convert(char(5), OfficeNumber) + Convert(char(10), CustomerNumber) As BCH_Customer
               FROM tblCustomers As x
               WHERE OfficeNumber = @Branch
               ) As y
              WHERE LostDate BETWEEN @FromDateA AND @ToDateA
              OR LostDate BETWEEN @FromDateB AND @ToDateB
              )  As C
 INNER JOIN (Select Convert(char(5), OfficeNumber) + Convert(char(10),CustomerNumber) As BCH_Customer
                   ,CASE WHEN MarketValue < 0.01 THEN CashBalance
                              ELSE MarketValue
                              END AS [Acct Value]
              FROM tblProducts
              WHERE OfficeNumber = @Branch
             )  As P
 ON       C.CustomerNumber = P.CustomerNumber AND
             C.OfficeNumber      = P.OfficeNumber
 GROUP BY
              DateRange
             ,C.BCH_Customer
             ,[Acct Value]
 WITH ROLLUP
 ORDER BY DateRange,C.BCH_Customer,[Acct Value]  DESC
  ) As Z
GO


ASKER CERTIFIED SOLUTION
Avatar of rafrancisco
rafrancisco

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial