Help How to concatenate an nvarchar field and a datetime type in SQL SERVER 2012

0

Good morning I wanted to know if you can help with the next query I want to concatenate an NVARCHAR field with a DATETIME this is my code

SELECT CONVERT (NVARCHAR(10), u.COMPROBANT)+' '+'del '+ CONVERT(VARCHAR(10),u.FECHA_TRS, 103) AS 'Comprobante #',m.COMPROBANT FROM
MOVIM AS m
LEFT JOIN ARTICULO AS a ON a.COD_ART = m.COD_ART 
LEFT JOIN BODEGA AS b ON b.COD_BODEGA = m.COD_BODEGA
LEFT JOIN T_UNI AS tu ON tu.COD_UNI = a.COD_UNI
LEFT JOIN USOMAT AS u ON u.COMPROBANT = m.COMPROBANT WHERE  u.FECHA_TRS IS NULL

but the result is that it does not concatenate me but sends me all NULL as it shows in the image

    
asked by Jose 17.04.2018 в 18:18
source

1 answer

0

The convert function is not performing it. Try cast

SELECT u.COMPROBANT +' '+'del '+ CAST(ISNULL(u.FECHA_TRS, '') AS NVARCHAR(10)) AS 'Comprobante #',m.COMPROBANT FROM
MOVIM AS m
LEFT JOIN ARTICULO AS a ON a.COD_ART = m.COD_ART 
LEFT JOIN BODEGA AS b ON b.COD_BODEGA = m.COD_BODEGA
LEFT JOIN T_UNI AS tu ON tu.COD_UNI = a.COD_UNI
LEFT JOIN USOMAT AS u ON u.COMPROBANT = m.COMPROBANT WHERE  u.FECHA_TRS IS NULL

But it is necessary that you assign some date format in specific, continue with convert

Now, if the value of your date is null, it is necessary to validate it with isnull ()

    
answered by 17.04.2018 в 18:22