Reddyrocks001 Ответов: 1

Ошибка преобразования при преобразовании значения varchar "Q1 26"В тип данных int.


SELECT   f.[asof_src_dt]
      ,f.[xfrm_asof_dt]
      ,f.[src_sys_nm]
      ,[actv_cat_id]
      ,[prd_ty_id]
      ,[brnd_id]
      ,[audnc_id]
      ,[actv_strt_dt_id]
      ,[actv_end_dt_id]
      ,[prtner_id]
      ,[ctry_id]
      ,[src_ctry_id]
      ,[spnd_ty_id]
      ,[sls_prtnr_id]
      ,[actv_ty_id]
      ,[spnd_dt_id]
      ,[ops_lvl_nm]
      ,[actv_sts_id]
      ,[clm_sts_id]
--,[intl_per]
,case when f.[src_sys_nm]='IION' then right([intl_per],2)+' '+left(intl_per,4)  
 when [intl_per]='NA' then 'NA' 
 else intl_per end as [intel_perd_new]
,case when f.[src_sys_nm]='IION' then convert(int,left([intl_per],4)+right(intl_per,1))  
 when [intl_per]='NA' then 999 
 else convert(int,right([intl_per],4)+right(left([intl_per],2),1)) end as [for_intel_period_sortkey]
,[oem_per]
      ,[tonnage_amt]
      ,[est_spend_amt]
      ,[act_spend_amt],e.actv_dtl_txt,e.budgt_ownr_nm,e.cmpgn_intv_cat_nm,e.cmpgn_invst_dtl_txt,e.fund_src_grp_nm,e.fund_src_nm,
e.spend_geo_org_nm,e.po_nbr,e.prim_busns_val_txt,e.submt_nm,e.spend_dsc,'' as proj_obj
  FROM [dbo].[fact_mktg_spend] f inner join
  [dbo].[fact_mktg_spend_ext] e
  on f.fact_mktg_spend_id=e.mkt_spnd_id
  inner join 
                [dbo].[dim_clndr]
on
f.[spnd_dt_id]=[dbo].[dim_clndr].[clndr_id]
where DATEPART(yyyy,clndr_dt)<=DATEPART(yyyy,DATEADD(yyyy,1,getdate()))
AND NOT(
[tonnage_amt] = 0 AND [est_spend_amt] = 0 AND [act_spend_amt] = 0)

UNION ALL

SELECT    [asof_src_dt]
      ,[xfrm_asof_dt]
      ,[src_sys_nm]
      ,[actv_cat_id]
      ,[prd_ty_id]
      ,[brnd_id]
      ,[audnc_id]
      ,isnull([actv_strt_dt_id],-1) AS actv_strt_dt_id
      ,isnull([actv_end_dt_id],-1) AS [actv_end_dt_id]
      ,[prtnr_id]
      ,[ctry_id]
,[src_ctry_id]
      ,[spnd_ty_id]
,[sls_prtner_id]
      ,[actv_ty_id]
      ,ISNULL([spnd_dt_id],-1) as spnd_dt_id
      ,[ops_lvl_nm]
   ,[actv_sts_id]
  ,[clm_sts_id]
      
  ,intel_perd
      ,CASE WHEN [intel_perd]='NA' THEN 999
ELSE convert(int,right(ltrim(rtrim([intel_perd])),4)+right(left(ltrim(rtrim([intel_perd])),2),1)) end AS [for_intel_period_sortkey]
      ,[oem_perd]
    ,[tonnage_amt]
      ,[est_spend_amt]
      ,[act_spend_amt]
     ,'' ,'','','','','','','','','','',[src_prog_obj_txt]
    FROM [dbo].[fact_art_rpt]
where [actv_strt_dt_id] is null

UNION all

SELECT   f.[asof_src_dt]
      ,f.[xfrm_asof_dt]
      ,f.[src_sys_nm]
      ,[actv_cat_id]
      ,[prd_ty_id]
      ,[brnd_id]
      ,[audnc_id]
      ,[actv_strt_dt_id]
      ,[actv_end_dt_id]
      ,[prtner_id]
      ,[ctry_id]
      ,[src_ctry_id]
      ,f.[spnd_ty_id]
      ,[sls_prtnr_id]
      ,[actv_ty_id]
      ,[spnd_dt_id]
      ,[ops_lvl_nm]
      ,[actv_sts_id]
      ,[clm_sts_id]
--,[intl_per]
,case when f.[src_sys_nm]='IION' then right([intl_per],2)+' '+left(intl_per,4)  
 when [intl_per]='NA' then 'NA' 
 else intl_per end as [intel_perd_new]
,case when f.[src_sys_nm]='IION' then convert(int,left([intl_per],4)+right(intl_per,1))  
 when [intl_per]='NA' then 999 
 else convert(int,right([intl_per],4)+right(left([intl_per],2),1)) end as [for_intel_period_sortkey]
,[oem_per]
      ,[tonnage_amt]
      ,[est_spend_amt]
      ,[act_spend_amt]
   ,'' ,'','','','','','','','','','',''
  FROM [dbo].[fact_mktg_spend] f
  inner join [dbo].[dim_spnd_ty] s
   on s.[spnd_ty_id]=f.[spnd_ty_id]
  inner join
                [dbo].[dim_clndr]
    
on
f.[spnd_dt_id]=[dbo].[dim_clndr].[clndr_id]
where DATEPART(yyyy,clndr_dt)<=DATEPART(yyyy,DATEADD(yyyy,1,getdate()))
AND NOT(
[tonnage_amt] = 0 AND [est_spend_amt] = 0 AND [act_spend_amt] = 0) and concat(f.src_sys_nm,s.spnd_ty_desc)!='MANUAL LOADDIRECT MERCH'
and f.src_sys_nm!= 'ART'


UNION ALL 
SELECT    [asof_src_dt]
      ,[xfrm_asof_dt]
      ,[src_sys_nm]
      ,[actv_cat_id]
      ,[prd_ty_id]
      ,[brnd_id]
      ,[audnc_id]
      ,isnull([actv_strt_dt_id],-1) AS actv_strt_dt_id
      ,isnull([actv_end_dt_id],-1) AS [actv_end_dt_id]
      ,[prtner_id]
      ,[ctry_id]
     , [src_ctry_id]
      ,[spnd_ty_id]
,[sls_prtner_id]
      ,[actv_ty_id]
      ,ISNULL([spnd_dt_id],-1) as spnd_dt_id
      ,[ops_lvl_nm]
   ,[actv_sts_id]
  ,[clm_sts_id]
                                                         
  ,intel_perd
      ,CASE WHEN [intel_perd]='NA' THEN 999
ELSE convert(int,right(ltrim(rtrim([intel_perd])),4)+right(left(ltrim(rtrim([intel_perd])),2),1)) end AS [for_intel_period_sortkey]

   ,[oem_perd]
    ,[tonnage_amt]
      ,[est_spend_amt]
      ,[act_spend_amt]
     ,'' ,'','','','','','','','','','',[src_prog_obj_txt]
    FROM [dbo].[fact_art_mdf_rpt]
       where src_sys_nm ='ART'


Что я уже пробовал:

Я не могу использовать isnumeric после преобразования
Пожалуйста помочь

RedDk

Без знания структуры таблицы невозможно что - либо сказать о преобразовании из одного типа в другой.

Dave Kreskowiak

Где - то находится та огромная куча запросов, которые вы пытаетесь преобразовать строку "Q1 26" в целое число. Не зная вообще ничего о структуре таблиц, о том, что хранится в каждом столбце (вы должны знать, в каком столбце находится эта строка!), и какая строка этого запроса вызвала ошибку, никто не сможет вам помочь.

1 Ответов

Рейтинг:
1

Santosh kumar Pithani

--varchar takes mixed vlaues but not integer---------
SELECT 
 CASE WHEN f.[src_sys_nm]='IION' THEN  CONCAT(LEFT([intl_per],4),RIGHT(intl_per,1))  
      WHEN [intl_per]='NA'       THEN '999' 
            ELSE  CONCAT(RIGHT([intl_per],4),RIGHT(LEFT([intl_per],2),1))
    END AS [for_intel_period_sortkey]