How to make multiple mask replaces per T-SQL table field

1

I'm doing replaces of some texts (Mask) of a field of a temporary table. I'm replacing where text is searched for by a field from other tables.

Example:

SELECT TOP 1000 * INTO #TEMP_COMPL_L FROM TB_CONTRATO WHERE IDCAR_CON = 1
ALTER TABLE #TEMP_COMPL_L ADD COMPL_TMP VARCHAR(1500)

UPDATE #TEMP_COMPL_L set COMPL_TMP = '#PRINOME#, URGENTE: Va a sua loja no dia #DATA# e procure o Gerente #NOMEGERENTE#.'

-- INSERIR DADOS DAS MÁSCARAS AQUI
UPDATE #TEMP_COMPL_L SET COMPL_TMP = 
REPLACE(
REPLACE(
REPLACE(COMPL_TMP,
    '#PRINOME#',LEFT(NOME_CLI, CHARINDEX(' ',NOME_CLI)-1))
    ,'#NOMEGERENTE#',ISNULL(CONTT_LOJ,''))
    ,'#DATA#',CONVERT(VARCHAR(10),GETDATE(),103)
    )
FROM #TEMP_COMPL_L INNER JOIN TB_CLIENTE ON IDCLI_CON = IDCLI_CLI
LEFT JOIN TB_LOJA ON IDLOJ_CON = IDLOJ_LOJ

That way it works perfectly, however, I will need to do this for more than 20 possible masks informed by the client, taking what is the mask and giving a replace for the value of the corresponding field of the STORE and CLIENT table.

There is a way to leave with a better performance and visibly readable, because several replaces will be very confused, in addition to having a limit of replaces in one go.

    
asked by anonymous 13.07.2017 / 17:56

0 answers