Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE [SNSMART_ANALISIS]
- GO
- /****** Object: StoredProcedure [SN].[pa_reporteRO] Script Date: 27/01/2017 10:00:07 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- ALTER procedure [SN].[pa_reporteRO] (
- @mes int,
- @anho int,
- @tiporegistro int
- )
- AS
- BEGIN
- declare @SecuenciaBien varchar(max)
- declare @SecuenciaOtorgante varchar(max)
- declare @idRegDesdeTipoReg int
- set @SecuenciaBien = ''
- set @idRegDesdeTipoReg = case @tiporegistro when 1 then 6 when 2 then 9 else 11 end
- delete from dbo.SecuenciaOtorgante
- DBCC CHECKIDENT ('SecuenciaOtorgante', RESEED, 0)
- declare @cuentaPorcj int,
- @idexpactox int,
- @auxIdExpActo int,
- @auxDefTipoInterv varchar(2),
- @TaTipoDefInterv varchar(2)
- set @cuentaPorcj = 0
- set @idexpactox = 0
- set @TaTipoDefInterv = ''
- set @auxIdExpActo = 0
- set @auxDefTipoInterv = ''
- declare @xParticipacion table (
- Ta_DefTipoInterv varchar(2),
- Td_IdExpedienteActo int,
- CountPersona int
- )
- insert into @xParticipacion
- select c.Ta_DefTipoInterv, a.Td_IdExpedienteActo, COUNT(a.tp_idpersona) as CountPersona
- from sn.td_expediente_interv as a
- inner join sn.tp_tipointerv as c on a.Tp_IdTipointerv = c.Tp_IdTipoInterv
- inner join SN.Tm_Escritura as d on a.Tm_IdExpediente = d.Tm_IdExpediente
- inner join SN.Td_Expediente_Acto as e on a.Td_IdExpedienteActo = e.Td_idexpedienteacto
- inner join SN.Tp_Actos as f on e.Tp_idacto = f.Tp_IdActo
- where c.Ta_DefTipoInterv in ('00', '01') and c.Tp_IdTipointerv <> 15 and MONTH(d.Tm_FechaGenEsc) = @mes and YEAR(d.Tm_FechaGenEsc) = @anho
- and d.Tm_idRegistro = @idRegDesdeTipoReg
- and not f.Ta_NatActo is null
- and not f.Tp_IdActo in (17, 24, 33, 104, 34, 147, 47, 125, 148, 119,
- 40,
- 39,
- 38,
- 37,
- 36,
- 35)
- and not d.Tm_idescritura in (4717, 4744, 5696, 6354, 6476, 6482, 6541, 7126, 7152, 7380, 8085, 8147, 8151, 8154, 8163, 8198, 8244, 8304, 8489, 8516) --- ESCRITURAS EXCLUIDAS
- group by c.Ta_DefTipoInterv, a.Td_IdExpedienteActo
- if @tiporegistro = 2
- begin
- select
- --ROW_NUMBER() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS Item,
- DENSE_RANK() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS ItemByEsc,
- 'I: Inicial' as TipoEnvioRO,
- case a.Tm_idRegistro when 6 then 'E : Escritura Pública' when 9 then 'T : Actas De Transferencia De Bienes Muebles Registrables' else 'G : Constitución De Garantía Mobiliaria Y Otras Afectaciones Sobre Bienes Muebles' end as tipoesc,
- convert(int, SUBSTRING(a.Tm_NumeroEscritura, 6, 5)) nroescritura,
- SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaNum,
- '' NroIPNPAclara,
- '' FechaIPNPAclara,
- 'C: Concluida' Conclusion,
- SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaFirmaParticip,
- 'U: Única' ModalidadOpe,
- '' CantMultiOpe,
- '' Representante,
- case i.Ta_DefTipoInterv when '00' then 'O: Ordenante /Propietario' else '' end PersonaOtorgante,
- case i.Ta_DefTipoInterv when '01' then 'B: Beneficiario /Adquirente' else '' end PersonaOtorgado,
- '' PersonaRepresenta,
- '' TipoRepresentacion,
- --SYSMART.ObtenerNaturalezaTaTabla(h.Ta_TipoIdentifica, 'Ta_TipoIdentifica') as TipoDoc,
- case h.Tp_Idtipopers when '00' then '' else '1: Residente' end as CondicionResidencia,
- case h.Tp_Idtipopers when '00' then '3: Jurídica' else '1: Natural' end as TipoPersona,
- case h.Tp_Idtipopers when '00' then '' else l.Ta_codigoROF + ': ' + l.Ta_nombreRof end as TipoDocumentoNat,
- case h.Tp_Idtipopers when '00' then '' else h.Numero end as NroDocNat,
- case h.Tp_Idtipopers when '00' then h.Numero else '' end as NroDocJur,
- case h.Tp_Idtipopers when '00' then h.RazonSocial else h.ApePaterno end as RazSocialOrApePaterno,
- case h.Tp_Idtipopers when '00' then '' else h.ApeMaterno end as ApeMaterno,
- case h.Tp_Idtipopers when '00' then '' else h.Nombres end as Nombres,
- case h.Tp_Idtipopers when '00' then '' else m.Ta_codigoROF + ': ' + m.Ta_nombreRof end as Nacionalidad,
- case h.Tp_Idtipopers when '00' then '' else SN.fc_formatearFecha('02', h.FechaNoC) end as FechaNac,
- case h.Tp_Idtipopers when '00' then '' else n.Ta_codigoROF + ': ' + n.Ta_nombreRof end as EstadoCivil,
- case h.Tp_Idtipopers when '00' then '' else h.CodOcupacionRO + ': ' + h.DescOcupacionRO end as OcupacionRO,
- case h.Tp_Idtipopers when '00' then '' else case h.CodOcupacionRO when '999' then case len(rtrim(LTRIM(h.Tp_NombreOcupacion))) when 0 then 'INDEPENDIENTE' else h. Tp_NombreOcupacion end else '' END end as DescripOcupacion,
- '' CIIU,
- '' CodCargo,
- '' CodZonaRegistral,
- '' NroPartidaRegistral,
- h.Direccion,
- oDep1.Tm_CodigoROF + ': ' + oDep1.tm_nombreROF as Departamento,
- oProv2.Tm_CodigoROF + ': ' + oProv2.tm_nombreROF as Provincia,
- oDist.Tm_CodigoROF + ': ' + oDist.tm_nombreROF as Distrito,
- '' Telefono,
- '' ParticipaConyuge,
- '' ApePaternoConyuge,
- '' ApeMaternoConyuge,
- '' NombresConyuge,
- r.Ta_codigoROF + ': ' + r.Ta_nombreRof as MedioPago,
- c.Tp_codigoROF + ': ' + c.Tp_nombreROF as TipoOperacion,
- q.tm_codigoROF + ': ' + q.tm_nombreROF as FormaPago,
- '99: Otro' as OportunidadPago,
- 'Con anterioridad a la firma del IP' as DescripOportuPago,
- case h.Tp_Idtipopers when '00' then '' else case i.Tp_IdTipoInterv when 15 then '' else 'Ahorro de trabajo' end end as OrigenDinero,
- s.tm_codigoROF + ': ' + s.tm_nombreROF as Moneda,
- CONVERT(varchar(20), convert(money, p.Td_ValorExpVeh), 1) as MontoOperacion,
- CONVERT(varchar(20), convert(money, p.Td_ValorExpVeh / j.CountPersona), 1) as MontoPorParticipante,
- CONVERT(varchar(20), convert(money, p.Td_ValorExpVeh), 1) as MontoRelacionado,
- CASE p.Tm_IdMoneda when 1 then '' when 2 then '2.821' when 3 then '3.521' end TipoCambio,
- 'I: Inscrito' InscripcionBien,
- case b.tp_idacto when 54 then '02: Chiclayo' else '09: Lima' end as CodZonaRegistral,
- t.Tp_PlacavVehiculo as Partida
- --,
- -- convert(varchar(max), round(100 / j.CountPersona, 2)) as porcentaje,
- -- j.CountPersona ,
- -- b.Td_idexpedienteacto,
- -- i.Ta_DefTipoInterv
- from SN.Tm_Escritura as a
- inner join SN.Td_Expediente_Acto as b on a.Tm_IdExpediente = b.Tm_idexpediente
- inner join SN.Tp_Actos as c on b.Tp_idacto = c.Tp_IdActo
- inner join SN.Td_Expediente_Interv as f on b.Td_idexpedienteacto = f.Td_IdExpedienteActo
- inner join SN.vstInterviniente2 as h on f.Tp_IdPersona = h.Tp_idpersona
- inner join SN.Tp_TipoInterv as i on f.Tp_IdTipointerv = i.Tp_IdTipoInterv
- inner join @xParticipacion j on b.Td_idexpedienteacto = j.Td_IdExpedienteActo and i.Ta_DefTipoInterv = j.Ta_DefTipoInterv
- inner join SYSMART.dbo.ta_tabla as l on h.Ta_TipoIdentifica = l.ta_codigo and l.ta_campo = 'Ta_TipoIdentifica'
- left join SYSMART.dbo.ta_tabla as m on h.Ta_Nacionalidad = m.ta_codigo and m.ta_campo = 'Ta_Nacionalidad'
- left join SYSMART.dbo.ta_tabla as n on h.Ta_EstCivil = n.ta_codigo and n.ta_campo = 'Ta_EstCivil'
- inner join SYSMART.dbo.tm_ubigeo as oDist on h.tm_idubigeo = oDist.tm_idubigeo
- inner join SYSMART.dbo.tm_ubigeo as oProv2 on oDist.tm_refcodigo_ubi = oProv2.tm_idubigeo
- inner join SYSMART.dbo.tm_ubigeo as oDep1 on oProv2.tm_refcodigo_ubi = oDep1.tm_idubigeo
- inner join SN.Td_Expediente_Vehiculo as p on b.Td_idexpedienteacto = p.Td_IdExpedienteActo
- inner join SYSMART.dbo.tm_forma_pago as q on p.Tm_Idformapago = q.tm_idformapago
- inner join SYSMART.dbo.ta_tabla as r on p.Ta_MedioPago = r.ta_codigo and r.ta_campo = 'Ta_MedioPago'
- inner join SYSMART.dbo.Tm_moneda as s on p.Tm_IdMoneda = s.tm_idmoneda
- inner join SN.Tp_Vehiculos as t on p.Tp_IdVehiculo = t.Tp_IdVehiculo
- where MONTH(a.Tm_FechaGenEsc) = @mes and YEAR(a.Tm_FechaGenEsc) = @anho
- and i.Ta_DefTipoInterv in ('00', '01')
- and f.Tp_IdTipointerv <> 15
- and a.Tm_idRegistro = @idRegDesdeTipoReg
- and not a.Tm_idescritura in (4717, 4744, 5696, 6354, 6476, 6482, 6541, 7126, 7152, 7380, 8085, 8147, 8151, 8154, 8163, 8198, 8244, 8304, 8489, 8516) --- ESCRITURAS EXCLUIDAS
- and not c.Ta_NatActo is null
- and not c.Tp_IdActo in (17, 24, 33, 104, 34, 147, 47, 125, 148, 119,
- 40,
- 39,
- 38,
- 37,
- 36,
- 35)
- and case s.tm_codigoROF when 'PEN' then (p.Td_ValorExpVeh / 2.821) when 'USD' then p.Td_ValorExpVeh else (p.Td_ValorExpVeh / 3.521) end > 2500
- end
- else if @tiporegistro = 1
- begin
- select
- --ROW_NUMBER() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS Item,
- DENSE_RANK() OVER(ORDER BY Tm_NumeroEscritura ASC) AS ItemByEsc,
- 'I: Inicial' as TipoEnvioRO,
- 'E : Escritura Pública' as tipoesc,
- convert(int, SUBSTRING(Tm_NumeroEscritura, 6, 5)) nroescritura,
- SN.fc_formatearFecha('03', Tm_FechaGenEsc) as fechaNum,
- '' NroIPNPAclara,
- '' FechaIPNPAclara,
- 'C: Concluida' Conclusion,
- SN.fc_formatearFecha('03', tm_fechafirmaesc) as fechaFirmaParticip,
- 'U: Única' ModalidadOpe,
- '' CantMultiOpe,
- '' Representante,
- case Ta_DefTipoInterv when '00' then 'O: Ordenante /Propietario' else '' end PersonaOtorgante,
- case Ta_DefTipoInterv when '01' then 'B: Beneficiario /Adquirente' else '' end PersonaOtorgado,
- '' PersonaRepresenta,
- '' TipoRepresentacion,
- CondicionResidencia,
- TipoPersona,
- TipoDocumentoNat,
- NroDocNat,
- NroDocJur,
- RazSocialOrApePaterno,
- ApeMaterno,
- Nombres,
- Nacionalidad,
- FechaNac,
- EstadoCivil,
- OcupacionRO,
- DescripOcupacion,
- '' CIIU,
- '' CodCargo,
- '' CodZonaRegistral,
- '' NroPartidaRegistral,
- Direccion,
- Departamento,
- Provincia,
- Distrito,
- '' Telefono,
- '' ParticipaConyuge,
- '' ApePaternoConyuge,
- '' ApeMaternoConyuge,
- '' NombresConyuge,
- MedioPago,
- TipoOperacion,
- FormaPago,
- '99: Otro' as OportunidadPago,
- 'Con anterioridad a la firma del IP' as DescripOportuPago,
- case Tp_Idtipopers when '00' then '' else case Tp_IdTipoInterv when 15 then '' else 'Ahorro de trabajo' end end as OrigenDinero,
- Moneda,
- MontoOperacion,
- MontoPorParticipante,
- MontoRelacionado,
- TipoCambio,
- 'I: Inscrito' InscripcionBien,
- CodZonaRegistral,
- Partida,
- * from (
- select a.Tm_NumeroEscritura,
- a.Tm_FechaGenEsc,
- a.tm_fechafirmaesc,
- i.Ta_DefTipoInterv,
- h.Tp_Idtipopers,
- i.Tp_IdTipoInterv,
- --SYSMART.ObtenerNaturalezaTaTabla(h.Ta_TipoIdentifica, 'Ta_TipoIdentifica') as TipoDoc,
- case h.Tp_Idtipopers when '00' then '' else '1: Residente' end as CondicionResidencia,
- case h.Tp_Idtipopers when '00' then '3: Jurídica' else '1: Natural' end as TipoPersona,
- case h.Tp_Idtipopers when '00' then '' else l.Ta_codigoROF + ': ' + l.Ta_nombreRof end as TipoDocumentoNat,
- case h.Tp_Idtipopers when '00' then '' else h.Numero end as NroDocNat,
- case h.Tp_Idtipopers when '00' then h.Numero else '' end as NroDocJur,
- case h.Tp_Idtipopers when '00' then h.RazonSocial else h.ApePaterno end as RazSocialOrApePaterno,
- case h.Tp_Idtipopers when '00' then '' else h.ApeMaterno end as ApeMaterno,
- case h.Tp_Idtipopers when '00' then '' else h.Nombres end as Nombres,
- case h.Tp_Idtipopers when '00' then '' else m.Ta_codigoROF + ': ' + m.Ta_nombreRof end as Nacionalidad,
- case h.Tp_Idtipopers when '00' then '' else SN.fc_formatearFecha('02', h.FechaNoC) end as FechaNac,
- case h.Tp_Idtipopers when '00' then '' else n.Ta_codigoROF + ': ' + n.Ta_nombreRof end as EstadoCivil,
- case h.Tp_Idtipopers when '00' then '' else h.CodOcupacionRO + ': ' + h.DescOcupacionRO end as OcupacionRO,
- case h.Tp_Idtipopers when '00' then '' else case h.CodOcupacionRO when '999' then case len(rtrim(LTRIM(h.Tp_NombreOcupacion))) when 0 then 'INDEPENDIENTE' else h. Tp_NombreOcupacion end else '' END end as DescripOcupacion,
- h.Direccion,
- oDep1.Tm_CodigoROF + ': ' + oDep1.tm_nombreROF as Departamento,
- oProv2.Tm_CodigoROF + ': ' + oProv2.tm_nombreROF as Provincia,
- oDist.Tm_CodigoROF + ': ' + oDist.tm_nombreROF as Distrito,
- r.Ta_codigoROF + ': ' + r.Ta_nombreRof as MedioPago,
- c.Tp_codigoROF + ': ' + c.Tp_nombreROF as TipoOperacion,
- q.tm_codigoROF + ': ' + q.tm_nombreROF as FormaPago,
- s.tm_codigoROF + ': ' + s.tm_nombreROF as Moneda,
- CONVERT(varchar(20), convert(money, p.Td_ValorExpTrans), 1) as MontoOperacion,
- CONVERT(varchar(20), convert(money, p.Td_ValorExpTrans / j.CountPersona), 1) as MontoPorParticipante,
- CONVERT(varchar(20), convert(money, p.Td_ValorExpTrans), 1) as MontoRelacionado,
- CASE p.Tm_IdMoneda when 1 then '' when 2 then '2.821' when 3 then '3.521' end TipoCambio,
- u.Tp_codigoROF + ': ' + u.Tp_nombreROF as CodZonaRegistral,
- t.Tp_Partida as Partida
- --,
- -- convert(varchar(max), round(100 / j.CountPersona, 2)) as porcentaje,
- -- j.CountPersona ,
- -- b.Td_idexpedienteacto,
- -- i.Ta_DefTipoInterv
- from SN.Tm_Escritura as a
- inner join SN.Td_Expediente_Acto as b on a.Tm_IdExpediente = b.Tm_idexpediente
- inner join SN.Tp_Actos as c on b.Tp_idacto = c.Tp_IdActo
- inner join SN.Td_Expediente_Interv as f on b.Td_idexpedienteacto = f.Td_IdExpedienteActo
- inner join SN.vstInterviniente2 as h on f.Tp_IdPersona = h.Tp_idpersona
- inner join SN.Tp_TipoInterv as i on f.Tp_IdTipointerv = i.Tp_IdTipoInterv
- inner join @xParticipacion j on b.Td_idexpedienteacto = j.Td_IdExpedienteActo and i.Ta_DefTipoInterv = j.Ta_DefTipoInterv
- inner join SYSMART.dbo.ta_tabla as l on h.Ta_TipoIdentifica = l.ta_codigo and l.ta_campo = 'Ta_TipoIdentifica'
- left join SYSMART.dbo.ta_tabla as m on h.Ta_Nacionalidad = m.ta_codigo and m.ta_campo = 'Ta_Nacionalidad'
- left join SYSMART.dbo.ta_tabla as n on h.Ta_EstCivil = n.ta_codigo and n.ta_campo = 'Ta_EstCivil'
- inner join SYSMART.dbo.tm_ubigeo as oDist on h.tm_idubigeo = oDist.tm_idubigeo
- inner join SYSMART.dbo.tm_ubigeo as oProv2 on oDist.tm_refcodigo_ubi = oProv2.tm_idubigeo
- inner join SYSMART.dbo.tm_ubigeo as oDep1 on oProv2.tm_refcodigo_ubi = oDep1.tm_idubigeo
- inner join SN.Td_Expediente_Transferencia as p on b.Td_idexpedienteacto = p.Td_IdExpedienteActo
- inner join SYSMART.dbo.tm_forma_pago as q on p.Tm_Idformapago = q.tm_idformapago
- inner join SYSMART.dbo.ta_tabla as r on p.Ta_MedioPago = r.ta_codigo and r.ta_campo = 'Ta_MedioPago'
- inner join SYSMART.dbo.Tm_moneda as s on p.Tm_IdMoneda = s.tm_idmoneda
- inner join SN.Tp_Predios as t on p.Tp_IdBien = t.Tp_IdPredio
- inner join SN.Tp_OficinaReg as u on t.Tp_IdOficinaReg = u.Tp_IdOficinaReg
- where MONTH(a.Tm_FechaGenEsc) = @mes and YEAR(a.Tm_FechaGenEsc) = @anho
- and i.Ta_DefTipoInterv in ('00', '01')
- and f.Tp_IdTipointerv <> 15
- and a.Tm_idRegistro = @idRegDesdeTipoReg
- and not a.Tm_idescritura in (4717, 4744, 5696, 6354, 6476, 6482, 6541, 7126, 7152, 7380, 8085, 8147, 8151, 8154, 8163, 8198, 8244, 8304, 8489, 8516) --- ESCRITURAS EXCLUIDAS
- and not c.Ta_NatActo is null
- and b.Tp_idacto not in (35, 36, 37, 38, 39, 40)
- and case s.tm_codigoROF when 'PEN' then (p.Td_ValorExpTrans / 2.821) when 'USD' then p.Td_ValorExpTrans else (p.Td_ValorExpTrans / 3.521) end > 2500
- ) as x
- end
- else
- begin
- select
- --ROW_NUMBER() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS Item,
- DENSE_RANK() OVER(ORDER BY a.Tm_NumeroEscritura ASC) AS ItemByEsc,
- 'I: Inicial' as TipoEnvioRO,
- case a.Tm_idRegistro when 6 then 'E : Escritura Pública' when 9 then 'T : Actas De Transferencia De Bienes Muebles Registrables' else 'G : Constitución De Garantía Mobiliaria Y Otras Afectaciones Sobre Bienes Muebles' end as tipoesc,
- convert(int, SUBSTRING(a.Tm_NumeroEscritura, 6, 5)) nroescritura,
- SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaNum,
- '' NroIPNPAclara,
- '' FechaIPNPAclara,
- 'C: Concluida' Conclusion,
- SN.fc_formatearFecha('03', a.tm_fechafirmaesc) as fechaFirmaParticip,
- 'U: Única' ModalidadOpe,
- '' CantMultiOpe,
- '' Representante,
- case i.Ta_DefTipoInterv when '00' then 'O: Ordenante /Propietario' else '' end PersonaOtorgante,
- case i.Ta_DefTipoInterv when '01' then 'B: Beneficiario /Adquirente' else '' end PersonaOtorgado,
- '' PersonaRepresenta,
- '' TipoRepresentacion,
- --SYSMART.ObtenerNaturalezaTaTabla(h.Ta_TipoIdentifica, 'Ta_TipoIdentifica') as TipoDoc,
- case h.Tp_Idtipopers when '00' then '' else '1: Residente' end as CondicionResidencia,
- case h.Tp_Idtipopers when '00' then '3: Jurídica' else '1: Natural' end as TipoPersona,
- case h.Tp_Idtipopers when '00' then '' else l.Ta_codigoROF + ': ' + l.Ta_nombreRof end as TipoDocumentoNat,
- case h.Tp_Idtipopers when '00' then '' else h.Numero end as NroDocNat,
- case h.Tp_Idtipopers when '00' then h.Numero else '' end as NroDocJur,
- case h.Tp_Idtipopers when '00' then h.RazonSocial else h.ApePaterno end as RazSocialOrApePaterno,
- case h.Tp_Idtipopers when '00' then '' else h.ApeMaterno end as ApeMaterno,
- case h.Tp_Idtipopers when '00' then '' else h.Nombres end as Nombres,
- case h.Tp_Idtipopers when '00' then '' else m.Ta_codigoROF + ': ' + m.Ta_nombreRof end as Nacionalidad,
- case h.Tp_Idtipopers when '00' then '' else SN.fc_formatearFecha('02', h.FechaNoC) end as FechaNac,
- case h.Tp_Idtipopers when '00' then '' else n.Ta_codigoROF + ': ' + n.Ta_nombreRof end as EstadoCivil,
- case h.Tp_Idtipopers when '00' then '' else h.CodOcupacionRO + ': ' + h.DescOcupacionRO end as OcupacionRO,
- case h.Tp_Idtipopers when '00' then '' else case h.CodOcupacionRO when '999' then case len(rtrim(LTRIM(h.Tp_NombreOcupacion))) when 0 then 'INDEPENDIENTE' else h. Tp_NombreOcupacion end else '' END end as DescripOcupacion,
- '' CIIU,
- '' CodCargo,
- '' CodZonaRegistral,
- '' NroPartidaRegistral,
- h.Direccion,
- oDep1.Tm_CodigoROF + ': ' + oDep1.tm_nombreROF as Departamento,
- oProv2.Tm_CodigoROF + ': ' + oProv2.tm_nombreROF as Provincia,
- oDist.Tm_CodigoROF + ': ' + oDist.tm_nombreROF as Distrito,
- '' Telefono,
- '' ParticipaConyuge,
- '' ApePaternoConyuge,
- '' ApeMaternoConyuge,
- '' NombresConyuge,
- '02: Cheque' as MedioPago,
- c.Tp_codigoROF + ': ' + c.Tp_nombreROF as TipoOperacion,
- 'P: A Plazos (Más De Una Cuota)' as FormaPago,
- '99: Otro' as OportunidadPago,
- 'Con anterioridad a la firma del IP' as DescripOportuPago,
- case h.Tp_Idtipopers when '00' then '' else case i.Tp_IdTipoInterv when 15 then '' else 'Ahorro de trabajo' end end as OrigenDinero,
- s.tm_codigoROF + ': ' + s.tm_nombreROF as Moneda,
- CONVERT(varchar(20), convert(money, p.Td_MontoGravamen), 1) as MontoOperacion,
- CONVERT(varchar(20), convert(money, p.Td_MontoGravamen/ j.CountPersona), 1) as MontoPorParticipante,
- CONVERT(varchar(20), convert(money, p.Td_MontoGravamen), 1) MontoRelacionado,
- CASE p.Tm_IdMoneda when 1 then '' when 2 then '2.821' when 3 then '3.521' end TipoCambio,
- 'I: Inscrito' InscripcionBien,
- case b.tp_idacto when 54 then '02: Chiclayo' else '09: Lima' end as CodZonaRegistral,
- t.Tp_PlacavVehiculo as Partida
- --,
- -- convert(varchar(max), round(100 / j.CountPersona, 2)) as porcentaje,
- -- j.CountPersona ,
- -- b.Td_idexpedienteacto,
- -- i.Ta_DefTipoInterv
- from SN.Tm_Escritura as a
- inner join SN.Td_Expediente_Acto as b on a.Tm_IdExpediente = b.Tm_idexpediente
- inner join SN.Tp_Actos as c on b.Tp_idacto = c.Tp_IdActo
- inner join SN.Td_Expediente_Interv as f on b.Td_idexpedienteacto = f.Td_IdExpedienteActo
- inner join SN.vstInterviniente2 as h on f.Tp_IdPersona = h.Tp_idpersona
- inner join SN.Tp_TipoInterv as i on f.Tp_IdTipointerv = i.Tp_IdTipoInterv
- inner join @xParticipacion j on b.Td_idexpedienteacto = j.Td_IdExpedienteActo and i.Ta_DefTipoInterv = j.Ta_DefTipoInterv
- inner join SYSMART.dbo.ta_tabla as l on h.Ta_TipoIdentifica = l.ta_codigo and l.ta_campo = 'Ta_TipoIdentifica'
- left join SYSMART.dbo.ta_tabla as m on h.Ta_Nacionalidad = m.ta_codigo and m.ta_campo = 'Ta_Nacionalidad'
- left join SYSMART.dbo.ta_tabla as n on h.Ta_EstCivil = n.ta_codigo and n.ta_campo = 'Ta_EstCivil'
- inner join SYSMART.dbo.tm_ubigeo as oDist on h.tm_idubigeo = oDist.tm_idubigeo
- inner join SYSMART.dbo.tm_ubigeo as oProv2 on oDist.tm_refcodigo_ubi = oProv2.tm_idubigeo
- inner join SYSMART.dbo.tm_ubigeo as oDep1 on oProv2.tm_refcodigo_ubi = oDep1.tm_idubigeo
- inner join SN.Td_Expediente_Gravamen as p on b.Td_idexpedienteacto = p.Td_IdExpedienteActo
- inner join SYSMART.dbo.Tm_moneda as s on p.Tm_IdMoneda = s.tm_idmoneda
- inner join SN.Tp_Vehiculos as t on p.Tp_idbien = t.Tp_IdVehiculo
- where MONTH(a.Tm_FechaGenEsc) = @mes and YEAR(a.Tm_FechaGenEsc) = @anho
- and i.Ta_DefTipoInterv in ('00', '01')
- and f.Tp_IdTipointerv <> 15
- and a.Tm_idRegistro = 11
- end
- end
Add Comment
Please, Sign In to add comment