How do I convert a date into varchar?

Asked

Viewed 32 times

0

How do I convert a date into varchar? I tried to convert to normal mode but couldn’t, could anyone help me? I want DT_PAGAMENTO to be in "03/02/2021" format, in dynamic mode.

SELECT
    NUMERO = CAST(SUBSTRING(BB.IDENT_TITULO, 8, LEN(BB.IDENT_TITULO)) AS BIGINT)
   ,VR_PAGO = CAST(AA.VLOR_PAGO AS FLOAT)/100
   ,DT_PAGAMETO = CONVERT(VARCHAR,AA.DATA_OCORRENCIA,103) <------
   ,DT_VENCIMENTO = BB.DATA_VENC_TITULO
INTO #PAGTO_SENAC
FROM
    #REGISTRO_DETALHE_U AA,
    #REGISTRO_DETALHE_T BB
WHERE
    AA.LOTE = BB.LOTE
    AND AA.ID = BB.ID

[date]

1

1 answer

0


Verify that the created temporary table generated the DATE type for the Payment Date.

It may be that the type is different from DATE and you are dealing with the wrong type.

Ex:

In the code below I am trying to convert a Varchar data into VARCHAR

 SELECT DT_PAGAMENTO = convert(varchar, '01022021',103) 
  • Thanks for your attention, but I was able to find a "shortcut" to solve this. If anyone else needs to know how it can work... SELECT DT_PAGAMETO = SUBSTRING(AA.DATA_OCORRENCIA, 1,2) + '/' + SUBSTRING(AA.DATA_OCORRENCIA,3,2) + '/' + SUBSTRING(AA.DATA_OCORRENCIA,5,4)

Browser other questions tagged

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