简体   繁体   中英

DB2 error on TSQL

I am getting this error: [OLE/DB provider returned message: [IBM][CLI Driver] [DB2 / linuxx8664] SQL0206N "LS_SCHEDULED_DATE" is not valid in the context where used. SQLSTATE=42703) OLE DB error trace [OLE /DB Provider 'MSDASQL' IColumnsInfo: GetColumnsInfo returned 0x80004005: Msg7339, Level 1, State 1, Line 83 OLE DB provider 'MSDASQL' reported an error.


The code I am getting this error is as follows:

IF OBJECT_ID('tempdb..#Temp1') is not null begin drop table #Temp1

select * 

into #Temp1
from openquery(LnkServer,

'
Select 
X.loan_number, 
X.ls_code,
x.ls_actual_completion_date
x.ls_scheduled_completion_date

,max(Case WHEN (ls_code = ''924'' and ls_scheduled_completion_date <> (''01/01/1900'')
             then ls_scheduled_completion_code
               else NULL End) as Ls_scheduled_completion_date

,max(Case WHEN (ls_code = ''926'' and ls_scheduled_completion_date <> (''01/01/1900'')
             then ls_scheduled_completion_code
               else NULL End) as Ls_scheduled_completion_date

,max(Case WHEN (ls_code = ''927'' and ls_scheduled_completion_date <> (''01/01/1900'')
             then ls_scheduled_completion_code
               else NULL End) as Ls_scheduled_completion_date

,max(Case WHEN (ls_code = ''928'' and ls_scheduled_completion_date <> (''01/01/1900'')
             then ls_scheduled_completion_code
               else NULL End) as Ls_scheduled_completion_date

from master x
     inner join(select loan_number, MAX(ls_scheduled_completion_date) as COMPL_DATE
                MAX(ls_actual_completion_date) as APPROVAL_DATE

     Where LS_code in (''924'', ''926'', ''927'', ''928'', ''D08'', ''H38'', ''H79'', ''H42'',
                       ''M40'', ''M29'', ''M10'', ''M40'', ''P31'', ''P49'', ''S17'')

      Group by loan_number order by loan_number) y
      on x.loan_number = y.loan_number
         and x.ls_scheduled_date = y.Compl_date
         and x.ls_actual_completion_date = y.approval_date
      Group by x.loan_number, x.ls_actual_completion_date, ls_scheduled_date

for fetch only with ur')

Don't you mean LS_SCHEDULED_COMPLETION_DATE ?

There doesn't appear to be a LS_SCHEDULED_DATE anywhere in the query other than in the on and group by clauses where I'm assuming the error is occurring.

From IBM's own publib site :

For a SELECT or DELETE statement, the specified column is not a column of any of the tables or views identified in a FROM clause in the statement.

Verify that the names are specified correctly in the SQL statement. For a SELECT statement, ensure that all the required tables are named in the FROM clause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM