use ABCVVV-- Current standard for jobs->projects mapping is via qslot->project mapping, maintained in the Coreman DB
-- Define temporary table with qslot->project mappings, to keep it alive during the query runtime
begin
declare @cashe table(
[idsid] [varchar](30) NULL,
[GLSuperGroupDes] [varchar](50) NULL,
[GLGroupDesc] [varchar](50) NULL,
[GLDivisionDesc] [varchar](50) NULL,
[GLCostCenterDes] [varchar](50) NULL,
[OrgUnitDescr] [varchar](50) NULL)

DECLARE @tmp_gtouret_coremanT TABLE
 (

      [proj_nm] [varchar](50) NULL,
      [actv_ty_nm] [varchar](255) NULL,
      [qslot_nm] [varchar](255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL
 
)
declare @GLSuperGroupDes varchar(50)
declare @GLGroupDesc varchar(50)
declare @GLDivisionDesc varchar(50)
declare @GLCostCenterDes varchar(50)
declare @OrgUnitDescr varchar(50)declare @Columns_Needed table
(   [Rid] [int] NULL,
[isSuccess] [varchar](50) NULL,
    [proj_nm] [varchar](50) NULL,
[clstr_nm] [varchar](50) NULL,
[mdl_nm] [varchar](100) NULL,
[user_idsid] [varchar](50) NULL,
[pool_dmn_nm] [varchar](50) NULL,
[pool_nm] [varchar](50) NULL,
[que_nm] [varchar](50) NULL,
    [qslot_nm] [varchar](255)  NULL,
[fini_dtm] [datetime] NULL,
[job_class] [varchar](50) NULL,
[cmd_txt] [varchar](150) NULL,
[runTime] [real] NULL,
[RTbucketlvl2] [varchar](50) NULL,
[RTbucketlvl1] [varchar](50) NULL,
    [GLSuperGroupDes] [varchar](50) NULL,
[GLGroupDesc] [varchar](50) NULL,
[GLDivisionDesc] [varchar](50) NULL,
[GLCostCenterDes] [varchar](50) NULL,
[OrgUnitDescr] [varchar](50) NULL
)
-- Populate the table based on Coreman mappings 
INSERT INTO @tmp_gtouret_coremanT (proj_nm,actv_ty_nm,qslot_nm)
select BM_Coreman_mstr_dmnd_drv_table.proj_nm,BM_Coreman_mstr_dmnd_drv_table.actv_ty_nm,BM_prj_que_slot_map_table.que_slot_nm as qslot_nm
from dbo.BM_prj_que_slot_map_table with (nolock)
  full outer join BM_Coreman_mstr_dmnd_drv_table with (nolock)
    on dbo.BM_Coreman_mstr_dmnd_drv_table.dmnd_drv_id=dbo.BM_prj_que_slot_map_table.dmnd_drv_id
 
 -- to sample the data, I take every 1000th record INSERT into @Columns_Needed([Rid]
      ,[isSuccess]
      ,[proj_nm]
      ,[clstr_nm]
      ,[mdl_nm]
      ,[user_idsid]
      ,[pool_dmn_nm]
      ,[pool_nm]
      ,[que_nm]
      ,[qslot_nm]
      ,[fini_dtm]
      ,[job_class]
      ,[cmd_txt]
      ,[runTime]
      ,[RTbucketlvl2]
      ,[RTbucketlvl1]
      ,[GLSuperGroupDes] 
  , [GLGroupDesc]
   ,[GLDivisionDesc]
   ,[GLCostCenterDes] 
  ,[OrgUnitDescr] )
select * from (
  select ROW_NUMBER() OVER(ORDER BY fini_dtm) AS Rid,
-- BBBBBM_Table.ShortIntelWorkweekName,
--       BBBBBM_Table.exit_cd,
--For every job now, we define whether it finished successfully or failed. The columns below describe the actual completion status
  --      V_ExitCodeMappingCategory.Level1,V_ExitCodeMappingCategory.Level2,
        CASE  V_ExitCodeMappingCategory.Successful
          WHEN 1 THEN 'Success'
          ELSE 'Failure'
        END as isSuccess,
--Project name as defined based on qslot->project mapping
        T.proj_nm,
--Cluster name aka DUT name – is defined by part of the validation jobs, describes what component is actually being tested. May impact runtime and memory parameters
        CASE 
           WHEN BBBBBM_Table.clstr_nm is NULL THEN 'ISNULL'
           ELSE BBBBBM_Table.clstr_nm
        END as clstr_nm,
--Model name is defined by part of the validation jobs, and might be a path 
-- Im parsing it to get the actual model name
        CASE 
           WHEN CHARINDEX('/', REVERSE(BBBBBM_Table.mdl_nm))-1>0 THEN RIGHT(BBBBBM_Table.mdl_nm, CHARINDEX('/', REVERSE(BBBBBM_Table.mdl_nm))-1)
           WHEN BBBBBM_Table.mdl_nm is NULL THEN 'ISNULL'
           ELSE BBBBBM_Table.mdl_nm
         END as mdl_nm,
        BBBBBM_Table.user_idsid as user_idsid,
        BBBBBM_Table.pool_dmn_nm as pool_dmn_nm,
        BBBBBM_Table.pool_nm as pool_nm ,
        BBBBBM_Table.cmpte_job_que_nm as que_nm,
        BBBBBM_Table.que_slot_nm as qslot_nm,
  --      BBBBBM_Table.submt_dtm,  
        BBBBBM_Table.fini_dtm as fini_dtm, 
     --   BBBBBM_Table.raw_cls_txt, 
      -- job class parsed from raw_cls_txt
     
    from dbo.BBBBBM_Table (nolock)
    full outer join dbo.V_ExitCodeMappingCategory with (nolock)
      on dbo.V_ExitCodeMappingCategory.Category=dbo.BBBBBM_Table.calc_exit_cd
    full outer join @tmp_gtouret_coremanT T
    on dbo.BBBBBM_Table.que_slot_nm = T.qslot_nm
        where
-- An indes in JLD table exists on fini_dtm - 
          BBBBBM_Table.fini_dtm>=getdate()-7
        and BBBBBM_Table.fini_dtm<getdate()
  --      and T.proj_nm = 'Ivybridge'
   --     and (BBBBBM_Table.tot_wall_clck_tm-BBBBBM_Table.tot_susp_tm)/3600>6
-- For runtime prediction I suggest to consider non-negative exit codes only
        and BBBBBM_Table.exit_cd>=0
-- Jobs submitted to virtual pool have 2 records in IBI - one for vpool, the other one for ppool
-- The filter below is intended to skip vpool entries and avoid records duplication
          and pool_nm NOT IN (
                select distinct cmpte_job_pool_nm
                from dbo.BM_NBStatusPools_Table (nolock)
                where virtl_pool_txt = 'true'
          )
-- "Noise reduction" filters
-- Some records have bad attributes, such as negative run time, etc
-- Filters below should remove them
          and BBBBBM_Table.tot_wall_clck_tm>=BBBBBM_Table.tot_susp_tm
                 and not (
             BBBBBM_Table.que_slot_nm IS NULL or
          BBBBBM_Table.cmpte_job_que_nm IS NULL or
           BBBBBM_Table.rsrc_set_nm IS NULL or
           BBBBBM_Table.host_nm IS NULL or
           BBBBBM_Table.pool_nm IS NULL or
           BBBBBM_Table.user_idsid IS NULL or
           BBBBBM_Table.tot_wall_clck_tm IS NULL OR
           BBBBBM_Table.tot_wall_clck_tm <= 0 or
           BBBBBM_Table.tot_user_tm IS NULL OR
           BBBBBM_Table.tot_user_tm < 0 or
           BBBBBM_Table.tot_sys_tm IS NULL OR
           BBBBBM_Table.tot_sys_tm < 0 or
           BBBBBM_Table.tot_wait_tm_nbr < 0 or
           DATEDIFF(ss,BBBBBM_Table.strt_dtm,BBBBBM_Table.fini_dtm) < 0
        )
) T
Where Rid % 20 =0
insert into @cashe select * from opendatasource('sqloledb','server=ABC003;uid=ABCuser;pwd=ABCpass;database=JLD_development').JLD_development.dbo.cdis_cache_finalinsert into opendatasource('sqloledb','server=ABC003;uid=ABCuser;pwd=ABCpass;database=JLD_development').JLD_development.dbo.[JLDMdl&Tst20to1ForRunTime]select * from @Columns_Needed T
select 
       T.[Rid]
      ,T.[isSuccess]
      ,T.[proj_nm]
      ,T.[clstr_nm]
      ,T.[mdl_nm]
      ,T.[user_idsid]
      ,T.[pool_dmn_nm]
      ,T.[pool_nm]
      ,T.[que_nm]
      ,T.[qslot_nm]
      ,T.[fini_dtm]
      ,T.[job_class]
      ,T.[cmd_txt]
      ,T.[runTime]
      ,T.[RTbucketlvl2]
      ,T.[RTbucketlvl1]
      ,C.[GLSuperGroupDes]
      ,C.[GLGroupDesc]
      ,C.[GLDivisionDesc]
      ,C.[GLCostCenterDes]
      ,C.[OrgUnitDescr] from @Columns_Needed T left join @cashe C
on T.user_idsid=C.idsidend 

解决方案 »

  1.   

    --try
    use ABC003-- Current standard for jobs->projects mapping is via qslot->project mapping, maintained in the Coreman DB
    -- Define temporary table with qslot->project mappings, to keep it alive during the query runtime
    begin
    declare @cashe table(
    [idsid] [varchar](30) NULL,
    [GLSuperGroupDes] [varchar](50) NULL,
    [GLGroupDesc] [varchar](50) NULL,
    [GLDivisionDesc] [varchar](50) NULL,
    [GLCostCenterDes] [varchar](50) NULL,
    [OrgUnitDescr] [varchar](50) NULL)DECLARE @tmp_gtouret_coremanT TABLE
     (  [proj_nm] [varchar](50) NULL,
      [actv_ty_nm] [varchar](255) NULL,
      [qslot_nm] [varchar](255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL
     
    )
    declare @GLSuperGroupDes varchar(50)
    declare @GLGroupDesc varchar(50)
    declare @GLDivisionDesc varchar(50)
    declare @GLCostCenterDes varchar(50)
    declare @OrgUnitDescr varchar(50)declare @Columns_Needed table
    ( [Rid] [int] NULL,
    [isSuccess] [varchar](50) NULL,
      [proj_nm] [varchar](50) NULL,
    [clstr_nm] [varchar](50) NULL,
    [mdl_nm] [varchar](100) NULL,
    [user_idsid] [varchar](50) NULL,
    [pool_dmn_nm] [varchar](50) NULL,
    [pool_nm] [varchar](50) NULL,
    [que_nm] [varchar](50) NULL,
      [qslot_nm] [varchar](255) NULL,
    [fini_dtm] [datetime] NULL,
    [job_class] [varchar](50) NULL,
    [cmd_txt] [varchar](150) NULL,
    [runTime] [real] NULL,
    [RTbucketlvl2] [varchar](50) NULL,
    [RTbucketlvl1] [varchar](50) NULL,
      [GLSuperGroupDes] [varchar](50) NULL,
    [GLGroupDesc] [varchar](50) NULL,
    [GLDivisionDesc] [varchar](50) NULL,
    [GLCostCenterDes] [varchar](50) NULL,
    [OrgUnitDescr] [varchar](50) NULL
    )
    -- Populate the table based on Coreman mappings 
    INSERT INTO @tmp_gtouret_coremanT (proj_nm,actv_ty_nm,qslot_nm)
    select BM_Coreman_mstr_dmnd_drv_table.proj_nm,BM_Coreman_mstr_dmnd_drv_table.actv_ty_nm,BM_prj_que_slot_map_table.que_slot_nm as qslot_nm
    from dbo.BM_prj_que_slot_map_table with (nolock)
      full outer join BM_Coreman_mstr_dmnd_drv_table with (nolock)
      on dbo.BM_Coreman_mstr_dmnd_drv_table.dmnd_drv_id=dbo.BM_prj_que_slot_map_table.dmnd_drv_id
     
     -- to sample the data, I take every 1000th record INSERT into @Columns_Needed([Rid]
      ,[isSuccess]
      ,[proj_nm]
      ,[clstr_nm]
      ,[mdl_nm]
      ,[user_idsid]
      ,[pool_dmn_nm]
      ,[pool_nm]
      ,[que_nm]
      ,[qslot_nm]
      ,[fini_dtm]
      ,[job_class]
      ,[cmd_txt]
      ,[runTime]
      ,[RTbucketlvl2]
      ,[RTbucketlvl1]
      ,[GLSuperGroupDes] 
    , [GLGroupDesc]
    ,[GLDivisionDesc]
    ,[GLCostCenterDes] 
    ,[OrgUnitDescr] )
    select * from (
      select ROW_NUMBER() OVER(ORDER BY fini_dtm) AS Rid,
    -- BBBBBM_Table.ShortIntelWorkweekName,
    -- BBBBBM_Table.exit_cd,
    --For every job now, we define whether it finished successfully or failed. The columns below describe the actual completion status
      -- V_ExitCodeMappingCategory.Level1,V_ExitCodeMappingCategory.Level2,
      CASE V_ExitCodeMappingCategory.Successful
      WHEN 1 THEN 'Success'
      ELSE 'Failure'
      END as isSuccess,
    --Project name as defined based on qslot->project mapping
      T.proj_nm,
    --Cluster name aka DUT name – is defined by part of the validation jobs, describes what component is actually being tested. May impact runtime and memory parameters
      CASE 
      WHEN BBBBBM_Table.clstr_nm is NULL THEN 'ISNULL'
      ELSE BBBBBM_Table.clstr_nm
      END as clstr_nm,
    --Model name is defined by part of the validation jobs, and might be a path 
    -- Im parsing it to get the actual model name
      CASE 
      WHEN CHARINDEX('/', REVERSE(BBBBBM_Table.mdl_nm))-1>0 THEN RIGHT(BBBBBM_Table.mdl_nm, CHARINDEX('/', REVERSE(BBBBBM_Table.mdl_nm))-1)
      WHEN BBBBBM_Table.mdl_nm is NULL THEN 'ISNULL'
      ELSE BBBBBM_Table.mdl_nm
      END as mdl_nm,
      BBBBBM_Table.user_idsid as user_idsid,
      BBBBBM_Table.pool_dmn_nm as pool_dmn_nm,
      BBBBBM_Table.pool_nm as pool_nm ,
      BBBBBM_Table.cmpte_job_que_nm as que_nm,
      BBBBBM_Table.que_slot_nm as qslot_nm,
      -- BBBBBM_Table.submt_dtm,  
      BBBBBM_Table.fini_dtm as fini_dtm, 
      -- BBBBBM_Table.raw_cls_txt, 
      -- job class parsed from raw_cls_txt
       
      from dbo.BBBBBM_Table (nolock)
      full outer join dbo.V_ExitCodeMappingCategory with (nolock)
      on dbo.V_ExitCodeMappingCategory.Category=dbo.BBBBBM_Table.calc_exit_cd
      full outer join @tmp_gtouret_coremanT T
      on dbo.BBBBBM_Table.que_slot_nm = T.qslot_nm
      where
    -- An indes in JLD table exists on fini_dtm - 
      BBBBBM_Table.fini_dtm>=getdate()-7
      and BBBBBM_Table.fini_dtm<getdate()
      -- and T.proj_nm = 'Ivybridge'
      -- and (BBBBBM_Table.tot_wall_clck_tm-BBBBBM_Table.tot_susp_tm)/3600>6
    -- For runtime prediction I suggest to consider non-negative exit codes only
      and BBBBBM_Table.exit_cd>=0
    -- Jobs submitted to virtual pool have 2 records in IBI - one for vpool, the other one for ppool
    -- The filter below is intended to skip vpool entries and avoid records duplication
      and pool_nm NOT IN (
      select distinct cmpte_job_pool_nm
      from dbo.BM_NBStatusPools_Table (nolock)
      where virtl_pool_txt = 'true'
      )
    -- "Noise reduction" filters
    -- Some records have bad attributes, such as negative run time, etc
    -- Filters below should remove them
      and BBBBBM_Table.tot_wall_clck_tm>=BBBBBM_Table.tot_susp_tm
      and not (
      BBBBBM_Table.que_slot_nm IS NULL or
      BBBBBM_Table.cmpte_job_que_nm IS NULL or
      BBBBBM_Table.rsrc_set_nm IS NULL or
      BBBBBM_Table.host_nm IS NULL or
      BBBBBM_Table.pool_nm IS NULL or
      BBBBBM_Table.user_idsid IS NULL or
      BBBBBM_Table.tot_wall_clck_tm IS NULL OR
      BBBBBM_Table.tot_wall_clck_tm <= 0 or
      BBBBBM_Table.tot_user_tm IS NULL OR
      BBBBBM_Table.tot_user_tm < 0 or
      BBBBBM_Table.tot_sys_tm IS NULL OR
      BBBBBM_Table.tot_sys_tm < 0 or
      BBBBBM_Table.tot_wait_tm_nbr < 0 or
      DATEDIFF(ss,BBBBBM_Table.strt_dtm,BBBBBM_Table.fini_dtm) < 0
      )
    ) T
    Where Rid % 20 =0
    insert into @cashe 
    select * from JLD_development.dbo.cdis_cache_finalinsert into JLD_development.dbo.[JLDMdl&Tst20to1ForRunTime]select * from @Columns_Needed T
    select 
      T.[Rid]
      ,T.[isSuccess]
      ,T.[proj_nm]
      ,T.[clstr_nm]
      ,T.[mdl_nm]
      ,T.[user_idsid]
      ,T.[pool_dmn_nm]
      ,T.[pool_nm]
      ,T.[que_nm]
      ,T.[qslot_nm]
      ,T.[fini_dtm]
      ,T.[job_class]
      ,T.[cmd_txt]
      ,T.[runTime]
      ,T.[RTbucketlvl2]
      ,T.[RTbucketlvl1]
      ,C.[GLSuperGroupDes]
      ,C.[GLGroupDesc]
      ,C.[GLDivisionDesc]
      ,C.[GLCostCenterDes]
      ,C.[OrgUnitDescr] from @Columns_Needed T left join @cashe C
    on T.user_idsid=C.idsidend
      

  2.   

    我差点摔倒!ABCVVV服务器上对应的代码是怎样?比如
    opendatasource('sqloledb','server=ABC003;uid=ABCuser;pwd=ABCpass;database=JLD_development')
    .JLD_development.dbo.cdis_