Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
5| Name | Data Type | Length | Description |
|---|---|---|---|
| @accion | varchar | 30 | |
| @p_contraparte | int | 4 | |
| @p_texto_nota | varchar | -1 | |
| @p_user_id | int | 4 | |
| @p_destacada | tinyint | 1 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_limite_credito_notas_
-- Add the parameters for the stored procedure here
@accion varchar(30) = null,
@p_contraparte int = null,
@p_texto_nota varchar(max) = null,
@p_user_id int = null,
@p_destacada tinyint = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @gestion int = null
if (@p_contraparte is null)
return
else begin
select @gestion = gestion
from LN_gestiones
where contraparte = @p_contraparte
and desde <= GETDATE()
and hasta >= GETDATE()
if (@gestion is null)
return
end
if (@accion = 'ingresar_nota') begin
DECLARE @usuario varchar(100) = null
if (@p_user_id is not null)
select @usuario = first_name + ' ' + last_name
from users where user_id = @p_user_id
DECLARE @horario varchar(16) = convert(varchar, getdate(), 103) + ' ' + left(convert(varchar,getdate(),14),5)
DECLARE @preffix varchar(120)
if @usuario is not null
SET @preffix = '['+@usuario+' - '+@horario+']: '
else
SET @preffix = '['+@horario+']: '
declare @nueva int
INSERT INTO LN_limite_credito_notas
(contraparte, gestion, texto_nota, created_by, destacada)
VALUES
(@p_contraparte, @gestion, iif(@p_texto_nota is not null, @preffix + @p_texto_nota, @preffix), @p_user_id, @p_destacada)
set @nueva = @@IDENTITY
select LN_limite_credito_notas.nota, LN_limite_credito_notas.contraparte,
LN_limite_credito_notas.gestion, LN_limite_credito_notas.texto_nota,
LN_limite_credito_notas.destacada,
convert(varchar, LN_limite_credito_notas.created, 103) + ' ' + left(convert(varchar,LN_limite_credito_notas.created,14),5) as ingresada,
convert(varchar, LN_limite_credito_notas.created, 121) as created,
LN_limite_credito_notas.created_by,
users.first_name, users.last_name, users.email,
clientes.nombre_cliente, padrones.nombre_persona, padrones.identificador,
padrones.numero, padrones.identificacion, identificadores.abreviatura,
identificadores.country_code, country.country_name
from LN_limite_credito_notas
inner join LN_contrapartes on LN_limite_credito_notas.contraparte = LN_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
inner join country on identificadores.country_code = country.country_code
inner join clientes on LN_contrapartes.cliente = clientes.cliente
left outer join users on LN_limite_credito_notas.created_by = users.user_id
where LN_limite_credito_notas.nota = @nueva
end
if (@accion = 'search') begin
select LN_limite_credito_notas.nota, LN_limite_credito_notas.contraparte,
LN_limite_credito_notas.gestion, LN_limite_credito_notas.texto_nota,
LN_limite_credito_notas.destacada,
convert(varchar, LN_limite_credito_notas.created, 103) + ' ' + left(convert(varchar,LN_limite_credito_notas.created,14),5) as ingresada,
convert(varchar, LN_limite_credito_notas.created, 121) as created,
LN_limite_credito_notas.created_by,
users.first_name, users.last_name, users.email,
clientes.nombre_cliente, padrones.nombre_persona, padrones.identificador,
padrones.numero, padrones.identificacion, identificadores.abreviatura,
identificadores.country_code, country.country_name
from LN_limite_credito_notas
inner join LN_contrapartes on LN_limite_credito_notas.contraparte = LN_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
inner join country on identificadores.country_code = country.country_code
inner join clientes on LN_contrapartes.cliente = clientes.cliente
left outer join users on LN_limite_credito_notas.created_by = users.user_id
where LN_limite_credito_notas.contraparte = @p_contraparte
and LN_limite_credito_notas.gestion = @gestion
order by LN_limite_credito_notas.created DESC
end
END
GO
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE OR ALTER PROCEDURE dbo.LN_limite_credito_notas_
-- Add the parameters for the stored procedure here
@accion varchar(30) = null,
@p_contraparte int = null,
@p_texto_nota varchar(max) = null,
@p_user_id int = null,
@p_destacada tinyint = 0
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @gestion int = null
if (@p_contraparte is null)
return
else begin
select @gestion = gestion
from LN_gestiones
where contraparte = @p_contraparte
and desde <= GETDATE()
and hasta >= GETDATE()
if (@gestion is null)
return
end
if (@accion = 'ingresar_nota') begin
DECLARE @usuario varchar(100) = null
if (@p_user_id is not null)
select @usuario = first_name + ' ' + last_name
from users where user_id = @p_user_id
DECLARE @horario varchar(16) = convert(varchar, getdate(), 103) + ' ' + left(convert(varchar,getdate(),14),5)
DECLARE @preffix varchar(120)
if @usuario is not null
SET @preffix = '['+@usuario+' - '+@horario+']: '
else
SET @preffix = '['+@horario+']: '
declare @nueva int
INSERT INTO LN_limite_credito_notas
(contraparte, gestion, texto_nota, created_by, destacada)
VALUES
(@p_contraparte, @gestion, iif(@p_texto_nota is not null, @preffix + @p_texto_nota, @preffix), @p_user_id, @p_destacada)
set @nueva = @@IDENTITY
select LN_limite_credito_notas.nota, LN_limite_credito_notas.contraparte,
LN_limite_credito_notas.gestion, LN_limite_credito_notas.texto_nota,
LN_limite_credito_notas.destacada,
convert(varchar, LN_limite_credito_notas.created, 103) + ' ' + left(convert(varchar,LN_limite_credito_notas.created,14),5) as ingresada,
convert(varchar, LN_limite_credito_notas.created, 121) as created,
LN_limite_credito_notas.created_by,
users.first_name, users.last_name, users.email,
clientes.nombre_cliente, padrones.nombre_persona, padrones.identificador,
padrones.numero, padrones.identificacion, identificadores.abreviatura,
identificadores.country_code, country.country_name
from LN_limite_credito_notas
inner join LN_contrapartes on LN_limite_credito_notas.contraparte = LN_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
inner join country on identificadores.country_code = country.country_code
inner join clientes on LN_contrapartes.cliente = clientes.cliente
left outer join users on LN_limite_credito_notas.created_by = users.user_id
where LN_limite_credito_notas.nota = @nueva
end
if (@accion = 'search') begin
select LN_limite_credito_notas.nota, LN_limite_credito_notas.contraparte,
LN_limite_credito_notas.gestion, LN_limite_credito_notas.texto_nota,
LN_limite_credito_notas.destacada,
convert(varchar, LN_limite_credito_notas.created, 103) + ' ' + left(convert(varchar,LN_limite_credito_notas.created,14),5) as ingresada,
convert(varchar, LN_limite_credito_notas.created, 121) as created,
LN_limite_credito_notas.created_by,
users.first_name, users.last_name, users.email,
clientes.nombre_cliente, padrones.nombre_persona, padrones.identificador,
padrones.numero, padrones.identificacion, identificadores.abreviatura,
identificadores.country_code, country.country_name
from LN_limite_credito_notas
inner join LN_contrapartes on LN_limite_credito_notas.contraparte = LN_contrapartes.contraparte
inner join padrones on LN_contrapartes.id_padron = padrones.id_padron
inner join identificadores on padrones.identificador = identificadores.identificador
inner join country on identificadores.country_code = country.country_code
inner join clientes on LN_contrapartes.cliente = clientes.cliente
left outer join users on LN_limite_credito_notas.created_by = users.user_id
where LN_limite_credito_notas.contraparte = @p_contraparte
and LN_limite_credito_notas.gestion = @gestion
order by LN_limite_credito_notas.created DESC
end
END
GO