无法获取查询刷新 - 外部数据查询

时间:2014-01-10 18:39:46

标签: sql excel-2010

我在SQL Server Studio中构建了一个查询,它运行正常。然后我作为数据连接导入到excel 2010中。然后进入数据>现有连接并将该连接添加到特定单元格。

查询运行时没有错误但什么也没有产生。当我删除前两个部分(drop table和create table)时,它会运行并产生结果。

表格Sandbox.dbo.Mktt_RRSP_Reporting_2013YE已创建。正如我所说,我可以在SQL Server中运行查询,没有问题。

DROP TABLE  
  Sandbox.dbo.Mktt_RRSP_Reporting_2013CU

SELECT DISTINCT 
    vm.Date,
    vm.IndividualId,
    vm.fullname,
    vm.MemberNum,
    va.AcctBranchName,
    va.AccountId,
    va.Classification,
    va.Category,
    va.Type_,
    va.SubType,
    va.Balance,
    CASE  
      WHEN va.Balance > 0 THEN

          CASE
            WHEN Classification = 'TFSA' and
                 Type_ = 'tfhisa'                                                 THEN 'Savings-TFSA'
            WHEN Type_ = 'rspvar'                                                 THEN 'Savings-RRSP'

            /*** Terms ***/     
            WHEN Type_ in ('tfsa')                                                THEN 'Terms-TFSA'
            WHEN SubType in ('LRSPNR','LRSPR','RSPE','RSPE3','RSPOPT','RSPPAY',
                             'RSPRE','RSPSE','RSPNR1','RSPRV')                    THEN 'Terms-RRSP'
            WHEN Type_ = 'resp'  or 
                 SubType in ('RESPE3','RESPE3_SD','RESPNR','RESPNR_SD','RESPR',
                             'RESPR_SD','RESPRE','RESPRE_SD','RESPRV','RESPSE',
                             'RESPSE_SD')                                         THEN 'Terms-RESP'

            /*** Mutual Funds ***/
            WHEN Classification = 'TFSAMutualFund' or 
                 SubType = 'SDTFSA'                                               THEN 'MutualFund-TFSA'
            WHEN Classification = 'RegMutualFund' and 
                 SubType in ('GRSP','LIF','LIRA','LRSP','RDSP','RLIF','RRSP',
                             'SDLEV','SDLIF','SDLIRA','SDLRSP','SDOPEN',
                             'SDRLIF','SDRSP','SDSRSP','SRSP')                    THEN 'MutualFund-RRSP'
            WHEN Classification = 'RegMutualFund' and 
                 SubType in ('RESP-F','RESP-I')                                   THEN 'MutualFund-RESP'

            /*** Group ***/
            WHEN Type_ = 'rspgrp'                                                 THEN 'Group-RRSP'
          END   
    ELSE ' '
  END as prodtype,
  CASE  
      WHEN va.Balance > 0 THEN

          CASE
            WHEN Classification = 'TFSA' and
                 Type_ = 'tfhisa'                                                 THEN 'TFSA'
            WHEN Type_ = 'rspvar'                                                 THEN 'RRSP'

            /*** Terms ***/     
            WHEN Type_ in ('tfsa')                                                THEN 'TFSA'
            WHEN SubType in ('LRSPNR','LRSPR','RSPE','RSPE3','RSPOPT','RSPPAY',
                             'RSPRE','RSPSE','RSPNR1','RSPRV')                    THEN 'RRSP'
            WHEN Type_ = 'resp'  or 
                 SubType in ('RESPE3','RESPE3_SD','RESPNR','RESPNR_SD','RESPR',
                             'RESPR_SD','RESPRE','RESPRE_SD','RESPRV','RESPSE',
                             'RESPSE_SD')                                         THEN 'RESP'

            /*** Mutual Funds ***/
            WHEN Classification = 'TFSAMutualFund' or 
                 SubType = 'SDTFSA'                                               THEN 'TFSA'
            WHEN Classification = 'RegMutualFund' and 
                 SubType in ('GRSP','LIF','LIRA','LRSP','RDSP','RLIF','RRSP',
                             'SDLEV','SDLIF','SDLIRA','SDLRSP','SDOPEN',
                             'SDRLIF','SDRSP','SDSRSP','SRSP')                    THEN 'RRSP'
            WHEN Classification = 'RegMutualFund' and 
                 SubType in ('RESP-F','RESP-I')                                   THEN 'RESP'

            /*** Group ***/
            WHEN Type_ = 'rspgrp'                                                 THEN 'RRSP'
          END   
    ELSE ' '
  END as regdtype
INTO
  Sandbox.dbo.Mktt_RRSP_Reporting_2014CU        
FROM 
  C1005.v_Member vm 
LEFT JOIN
  C1005.v_Account va
ON
  vm.MemberId = va.MemberId and
  vm.Date     = va.date
WHERE
  vm.CurrentDate = 1 and
  va.CurrentDate = 1 and
  va.Isactive = 'Yes' and 
  vm.MemberStatus = 'active' and 
  vm.MemberClass = 'Consumer' and
  va.IsRegistered = 'Yes' and
  va.SubType NOT LIKE '%rif%' and
  va.SubType NOT LIKE '%SDRLSP%' and
  va.Type_ NOT LIKE '%rif%' and
  va.Balance > 0
ORDER BY
 prodtype
  --vm.IndividualId




/*********************** combine tables **************************/
SELECT DISTINCT 
    a.IndividualId,
    a.fullname,
    a.MemberNum,
    a.AcctBranchName,
    a.AccountId,
    a.Classification,
    a.Category,
    a.Type_,
    a.SubType,
    a.Balance as balance_curr,
    b.Balance as balance_2013,
    a.prodtype,
    a.regdtype,
    CASE
      WHEN b.balance IS NULL THEN a.balance 
      ELSE a.balance - b.balance
    END as Diffbalance,
    CASE 
      WHEN b.balance IS NULL THEN 1
      ELSE                        0
    END as flag_new
FROM
  Sandbox.dbo.Mktt_RRSP_Reporting_2014CU a
LEFT JOIN
  Sandbox.dbo.Mktt_RRSP_Reporting_2013YE  b
ON 
  a.accountid = b.accountid
ORDER BY
  flag_new,
  a.individualid

0 个答案:

没有答案