Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
3| Name | Data Type | Length | Description |
|---|---|---|---|
| @p_cliente | int | 4 | |
| @p_user_id | int | 4 | |
| @p_id_producto | int | 4 |
SQL Script
Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE dbo.limites_consumos_usuarios_productos
@p_cliente int,
@p_user_id int,
@p_id_producto int
AS
BEGIN
SET NOCOUNT ON;
declare @p_limite_cliente int;
declare @p_limites_usuarios int;
if (@p_user_id = '' or @p_user_id is null)
begin
set @p_user_id = '0'
end
set @p_limite_cliente = 0
set @p_limites_usuarios = 0
set @p_limite_cliente = (select clientes_productos.limite_consumo
from clientes_productos
where cliente = @p_cliente
and id_producto = @p_id_producto )
set @p_limites_usuarios = (select sum(isnull(a.limite_consumo,0))
from usuarios_productos a
where a.cliente = @p_cliente
and a.id_producto = @p_id_producto
and a.user_id != @p_user_id
and a.activo = '1'
and a.id_seccion =
(select min(id_seccion)
from usuarios_productos b
where b.cliente = @p_cliente
and b.user_id = a.user_id
and b.id_producto = a.id_producto
and b.activo = '1')
)
select @p_limite_cliente as limite_cliente, @p_limites_usuarios as limites_usuarios
END
GO
GO
CREATE OR ALTER PROCEDURE dbo.limites_consumos_usuarios_productos
@p_cliente int,
@p_user_id int,
@p_id_producto int
AS
BEGIN
SET NOCOUNT ON;
declare @p_limite_cliente int;
declare @p_limites_usuarios int;
if (@p_user_id = '' or @p_user_id is null)
begin
set @p_user_id = '0'
end
set @p_limite_cliente = 0
set @p_limites_usuarios = 0
set @p_limite_cliente = (select clientes_productos.limite_consumo
from clientes_productos
where cliente = @p_cliente
and id_producto = @p_id_producto )
set @p_limites_usuarios = (select sum(isnull(a.limite_consumo,0))
from usuarios_productos a
where a.cliente = @p_cliente
and a.id_producto = @p_id_producto
and a.user_id != @p_user_id
and a.activo = '1'
and a.id_seccion =
(select min(id_seccion)
from usuarios_productos b
where b.cliente = @p_cliente
and b.user_id = a.user_id
and b.id_producto = a.id_producto
and b.activo = '1')
)
select @p_limite_cliente as limite_cliente, @p_limites_usuarios as limites_usuarios
END
GO
Depends On
2Used By
No items found