EXECUTE [SQL] AT [LINKEDSERVER]返回不同的结果

时间:2018-03-30 17:26:52

标签: sql sql-server execute linked-server

我不太喜欢使用openquery(),代码太长了。我已经使用EXECUTE [SQL] AT [LINKEDSERVER]来获得结果;但是,执行此操作会返回不同于直接在Oracle服务器上运行的结果集。我粘贴了以下代码的摘录。这是更大的UNION的一部分,但即使这样也会返回不同的行数。我不知道发生了什么。

declare @strSQL varchar(max)

set @strSQL = N'select distinct saradap_pidm as PIDM
                 ,saradap_term_code_entry as TERMCODE
                 ,replace(saradap_program_1,''+'','''') as PROGRAM
                 ,''A'' as GROUPINGDATA
  from swradap
  inner join saradap
    on swradap_pidm = saradap_pidm
    and swradap_appl_no = saradap_appl_no
    and swradap_term_code_entry = saradap_term_code_entry
    where saradap_term_code_entry in (201810,201710)
    and not exists (select ''x''
                    from saradap s2
                    cross join (select to_date(''31-JAN-18'',''dd-MON-YY'') - to_date(''30-MAR-18'',''dd-MON-YY'') as L1
                                from dual) a1
                    where s2.saradap_pidm = swradap_pidm
                    and s2.saradap_appl_no = swradap_appl_no
                    and s2.saradap_apst_code = ''W''
                    and s2.saradap_term_code_entry = swradap_term_code_entry
                    and s2.saradap_apst_date <= case when swradap_term_code_entry = 201810
                                                           then ''30-MAR-18''
                                                           else trim(to_date(''25-JAN-17'',''dd-MON-YY'')-L1) end)
    and swradap_activity_date = (select max(s2.swradap_activity_date)
                                from swradap s2
                                cross join (select to_date(''31-JAN-18'',''dd-MON-YY'') - to_date(''30-MAR-18'',''dd-MON-YY'') as L1
                                            from dual) a1
                                where s2.swradap_pidm = saradap_pidm
                                and s2.swradap_appl_no = saradap_appl_no
                                and s2.swradap_term_code_entry = saradap_term_code_entry
                                and s2.swradap_activity_date <= case when saradap_term_code_entry = 201810
                                                                     then ''30-MAR-18''
                                                                     else trim(to_date(''25-JAN-17'',''dd-MON-YY'')-L1) end)'

execute (@strSQL) AT [PROD]

1 个答案:

答案 0 :(得分:0)

我可能已经弄清楚了。看起来如果我更换&#39; 30-MAR-18&#39;&#39;修剪(to_date(&#39;&#39; 30-MAR-18&#39;&#39;&#39; dd-MON-YY&#39;&#39;))然后它作品。我现在有新问题,但至少已经解决了。