Home > Back-end >  How can i do a concat() in SQL 2008
How can i do a concat() in SQL 2008

Time:05-23

I have this statement, which works in SQL Server 2017:

REPLACE(CONCAT(NOM_TIPO_QUEBRA_ORDEM, CHAR(13), DSC_TIPO_QUEBRA_ORDEM, CHAR(13), HST_ORDEM_FILA_MOVIMENTO), CHAR(13)   CHAR(13), '') as justificativa_quebra

How can I do this same in SQL Server 2008, which does not support CONCAT?

REPLACE(SELECT NOM_TIPO_QUEBRA_ORDEM, CHAR(13)   DSC_TIPO_QUEBRA_ORDEM, CHAR(13)   HST_ORDEM_FILA_MOVIMENTO), CHAR(13)   CHAR(13), '' as justificativa_quebra

CodePudding user response:

CONCAT(a,b,c) is just syntactic sugar for COALESCE(a,'') COALESCE(b,'') COALESCE(c,'').

So:

REPLACE
(
   CONCAT
   (
     NOM_TIPO_QUEBRA_ORDEM, CHAR(13),
     DSC_TIPO_QUEBRA_ORDEM, CHAR(13), 
     HST_ORDEM_FILA_MOVIMENTO
   ),  
CHAR(13)   CHAR(13), '') as justificativa_quebra

Becomes:

REPLACE(
    COALESCE(NOM_TIPO_QUEBRA_ORDEM,'')   char(13)
    COALESCE(DSC_TIPO_QUEBRA_ORDEM,'')   char(13)
    COALESCE(HST_ORDEM_FILA_MOVIMENTO, ''), 
CHAR(13)   CHAR(13), '') as justificativa_quebra

Next, send some feedback up the chain that using a database platform so famously out of support is just not a great idea.

  • Related