Error in converting dates during an Index

Asked

Viewed 340 times

1

I need to load a table into a database with data from another table and another database. It turns out that in the Datetime field is giving a conversion error, because the data of the other table is in Varchar. See how I did:

use [Rup]
insert into [dbo].[Ruptura]
(
    DataRuptura ===>>> AQUI DÁ O ERRO
    ,[IDJustificativa]
    ,[IDOrigem]
    ,[CodigoPDV]
    ,[Codigo_Apresentacao]
)

select

Convert(DateTime,stg.DATA,103)==>> Tentativa e não deu certo
,mot.MOTNM_CODIGO AS RUPTURA
,1 AS ORIGEM
,pdv.PDVCH_CODIGO AS CODIGO_PDV
,apr.APRCH_COD_ACHE AS CODIGO_EAN
from [STG_Rup].[dbo].[RPT_STG_CARGA] stg
join [STG_Rup].[dbo].[RPT_CAT_MOTIVO_RUPTURA] mot on stg.JUSTIFICATIVA = mot.MOTCH_MOTIVO_RUPTURA
join [STG_Rup].[dbo].[MDTR_CAT_PDV] pdv on stg.CNPJ = pdv.PDVCH_CNPJ
join [STG_Rup].[dbo].[VDA_CAT_APRESENTACAO] apr on stg.EAN = apr.APRCH_COD_EAN

The stg.Data field is a varchar(100)

2 answers

1


Solved:

.....
select

Convert(DateTime,Substring(stg.DATA,0,10))==>> Aqui resolvi
,mot.MOTNM_CODIGO AS RUPTURA
,1 AS ORIGEM
,pdv.PDVCH_CODIGO AS CODIGO_PDV
,apr.APRCH_COD_ACHE AS CODIGO_EAN
from [STG_Ruptura].[dbo].[RPT_STG_CARGA_ABILITY] stg
left join [STG_Ruptura].[dbo].[RPT_CAT_MOTIVO_RUPTURA] mot on stg.JUSTIFICATIVA = mot.MOTCH_MOTIVO_RUPTURA
left join [STG_Ruptura].[dbo].[MDTR_CAT_PDV] pdv on stg.CNPJ = pdv.PDVCH_CNPJ
left join [STG_Ruptura].[dbo].[VDA_CAT_APRESENTACAO] apr on stg.EAN = apr.APRCH_COD_EAN

0

Check the format this string is in; some see this link

Just yesterday "I drove that cart"; I passed a select with (@"{0:MM/dd/yyyy HH:mm:ss}; then changed to (@"{0:yyyy-MM-dd hh:mm:ss}.

An "unambiguous" format would be YYYYMMDD, but I did not test this.

Good luck, in case you haven’t made it yet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.