Código:
DECLARE @FECHAACTUAL AS DATETIME, @FECHAINI AS VARCHAR(20),@FECHAFIN AS VARCHAR(20), @PRUEBA AS VARCHAR(10) SET @FECHAACTUAL = GETDATE() SET @FECHAINI = CONVERT(VARCHAR(20),@FECHAACTUAL,112) SET @FECHAFIN = CONVERT(VARCHAR(20),DATEADD(DAY,1,@FECHAACTUAL),112) PRINT @FECHAACTUAL PRINT @FECHAINI PRINT @FECHAFIN DECLARE @XmlOutput xml SET @XmlOutput = ( select CASE Kw4.keyvaluesmall WHEN '1' then 'CC' WHEN '2' then 'NI' WHEN '3' then 'TI' WHEN '4' then 'CE' WHEN '7' then 'RC' WHEN '8' then 'NU' WHEN '9' then 'MS' END as [TipoIdent], Kw3.keyvaluebig as [NroIdentificacion], CASE Kw4.keyvaluesmall WHEN '1' then 'CC' WHEN '2' then 'NI' WHEN '3' then 'TI' WHEN '4' then 'CE' WHEN '7' then 'RC' WHEN '8' then 'NU' WHEN '9' then 'MS' END as [TipoIdentNueva], Kw5.keyvaluebig as [NroIdentificacionNueva], '' as [ParteAlfabetica], kw6.keyvaluechar as [Estadocivil], kw7.keyvaluechar as [Genero], kw8.keyvaluechar as [Direccion], kw9.keyvaluesmall as [Telefono], kw10.keyvaluechar as [Barrio], kw11.keyvaluesmall as [Ciudad], '999' as [Zona], kw13.keyvaluechar as [TipoDireccion], '' as [Extension], '830049724' as [Usuario] from HSI.ITEMDATA ID INNER JOIN HSI.ITEMDATAPAGE IDP on (ID.itemnum = IDP.itemnum) LEFT JOIN hsi.keyitem149 kw2 with(NOLOCK) ON kw2.itemnum = id.itemnum --Tipo de Identificación LEFT JOIN hsi.keyitem169 kw3 with(NOLOCK) ON kw3.itemnum = id.itemnum --Número de identificación LEFT JOIN hsi.keyitem149 kw4 with(NOLOCK) ON kw4.itemnum = id.itemnum --Tipo de Identificación Nueva LEFT JOIN hsi.keyitem169 kw5 with(NOLOCK) ON kw5.itemnum = id.itemnum --Número de identificación Nueva LEFT JOIN hsi.keyitem228 kw6 with(NOLOCK) ON kw6.itemnum = id.itemnum --Estadocivil LEFT JOIN hsi.keyitem420 kw7 with(NOLOCK) ON kw7.itemnum = id.itemnum --Genero LEFT JOIN hsi.keyitem422 kw8 with(NOLOCK) ON kw8.itemnum = id.itemnum --Direccion LEFT JOIN hsi.keyitem423 kw9 with(NOLOCK) ON kw9.itemnum = id.itemnum --Telefono LEFT JOIN hsi.keyitem379 kw10 with(NOLOCK) ON kw10.itemnum = id.itemnum --Barrio LEFT JOIN hsi.keyitem207 kw11 with(NOLOCK) ON kw11.itemnum = id.itemnum --Ciudad LEFT JOIN hsi.keyitem933 kw12 with(NOLOCK) ON kw12.itemnum = id.itemnum --Zona LEFT JOIN hsi.keyitem580 kw13 with(NOLOCK) ON kw13.itemnum = id.itemnum --Tipo direccion LEFT JOIN hsi.keyitem676 kw14 with(NOLOCK) ON kw14.itemnum = id.itemnum --Usuario LEFT OUTER JOIN HSI.keyrecorddata271 KG271 ON (ID.ITEMNUM = KG271.ITEMNUM) --No. ID Documento where ID.ITEMTYPENUM IN(1046) --AND kw3.keyvaluebig=1012422115 AND ID.itemdate BETWEEN @FECHAINI AND @FECHAFIN FOR XML PATH('Actualiza'), ROOT('ACTUALIZACION') , ELEMENTS ) ---Salida del Archivo en XML SELECT @XmlOutput as Datos