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')