当列等于特定值时添加字符串

时间:2018-02-16 16:00:31

标签: sql sql-server stored-procedures

我有这样的存储过程:

DECLARE @comando as varchar(5000)

    set @comando = 'DTEXEC  /FILE \"" /de "pass" /CHECKPOINTING OFF  /REPORTING EW'
    select @comando = @comando + ' /SET "\"\Package.Variables[' + Replace(str_NombreVariable,'User::','') + '].Value\"";' 
   + str_ValorVariable + ''
from [Catalogo].[catVariablesEtl] where IdPaquete = 42

我收到这样的大件物品:

DTEXEC  /FILE \"" /de "pass" /CHECKPOINTING OFF  /REPORTING EW /SET "\"\Package.Variables[v_sTipoCarga].Value\"";M /SET "\"\Package.Variables[v_sUsuarioCarga].Value\"";0 /SET "\"\Package.Variables[v_sCadenaConexion].Value\"";"\"Data Source=0.0.0.0.0\DB;User ID=BB;Password=BBA;Initial Catalog=BS;Persist Security Info=True;Initial Catalog=BBS;Persist Security Info=True;\"" /SET "\"\Package.Variables[v_sCadenaConexionSAP].Value\"";"\"TYPE=A; ASHOST=0.0.0.0.0; SYSNR=70; CLIENT=720; LANG=ES; USER=BB; PASSWD=BB1;\"" /SET "\"\Package.Variables[v_sRutaArchivo].Value\"";"\"\\0.0.0.0\SIBISharedFolder\Source\CargaMaquinas\ /SET "\"\Package.Variables[v_IdBitacoraCarga].Value\"";0

倒数第二个值为Package.Variables[v_sRutaArchivo].Valuestr_ValorVariable等于\\0.0.0.0\SIBISharedFolder\Source\CargaMaquinas\,我想知道是否可以通过搜索此项来向此选择添加字符串:v_sRutaArchivo in str_NombreVariable当它发现添加到str_ValorVariable.csv

有可能实现吗?

1 个答案:

答案 0 :(得分:0)

DECLARE @comando as varchar(5000)

set @comando = 'DTEXEC  /FILE \"" /de "pass" /CHECKPOINTING OFF  /REPORTING EW'
select @comando = @comando + ' /SET "\"\Package.Variables[' + Replace(str_NombreVariable,'User::','') + '].Value\"";' 
   + str_ValorVariable + CASE WHEN str_NombreVariable like '%v_sRutaArchivo%' THEN '.csv' ELSE '' END + ''
from [Catalogo].[catVariablesEtl] where IdPaquete = 42