Bom dia povo... Como estão?

Alguém pode me ajudar ai???

Preciso saber se em uma procedure, quando eu colocar nível de isolamento, tenho que colocar somente no começo da execução ou em cada select?

Exemplo1:

USE [bdTeste]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp_CarteiraPedido] @Parcial INT, @Filial VARCHAR(2)
AS
DECLARE @vlTotalPen AS FLOAT
DECLARE @vlTotal AS FLOAT

BEGIN
Set transaction isolation level READ UNCOMMITTED
--Verifica o valor total da Carteira
SELECT
@vlTotalPen = round(SUM(vcg.Vl_SemReserv),8),
@vlTotal = round(SUM(vcg.Vl_Reserv + vcg.Vl_SemReserv),8)
FROM Vw_CarteiraGer vcg
WHERE vcg.Empresa = '01' and vcg.Filial in (@Filial) AND vcg.FatParcial in (@Parcial)

--Busca as informações para a grid

SELECT
vcg.Empresa, vcg.Filial, vcg.CodOrcamento_id, vcg.Nome, vcg.CodVendedor_ID,
SUM(CASE WHEN ISNULL(vcg.Qt_SemReserv, 0) = 0 THEN 0 ELSE 1 END) AS QtdPend,
ROUND(SUM(vcg.Vl_SemReserv), 2) AS VlPend,
ROUND(((SUM(vcg.Vl_SemReserv) /@vlTotalPen)*100),8) AS Acumulado,
'' AS Acumulado2,
ROUND(SUM(vcg.Vl_Reserv + vcg.Vl_SemReserv), 2) AS VLTotal,
ROUND(((SUM(vcg.Vl_Reserv + vcg.Vl_SemReserv) /@vlTotal)*100),8) AS PercCartT,
SUM(CASE WHEN ISNULL(vcg.Qt_Reserv, 0) = 0 THEN 0 ELSE 1 END) AS QtdDisp,
COUNT(vcg.NITEM) AS ITENS
FROM Vw_CarteiraGer vcg
WHERE vcg.Empresa = '01' and vcg.Filial in (@Filial) AND vcg.FatParcial in (@Parcial)
GROUP BY vcg.Empresa, vcg.Filial, vcg.CodOrcamento_id, vcg.Nome, vcg.CodVendedor_ID
ORDER BY VlPend DESC

END

Exemplo2:

USE [bdTeste]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp_CarteiraPedido] @Parcial INT, @Filial VARCHAR(2)
AS
DECLARE @vlTotalPen AS FLOAT
DECLARE @vlTotal AS FLOAT

BEGIN
Set transaction isolation level READ UNCOMMITTED
--Verifica o valor total da Carteira
SELECT
@vlTotalPen = round(SUM(vcg.Vl_SemReserv),8),
@vlTotal = round(SUM(vcg.Vl_Reserv + vcg.Vl_SemReserv),8)
FROM Vw_CarteiraGer vcg
WHERE vcg.Empresa = '01' and vcg.Filial in (@Filial) AND vcg.FatParcial in (@Parcial)

--Busca as informações para a grid
Set transaction isolation level READ UNCOMMITTED
SELECT
vcg.Empresa, vcg.Filial, vcg.CodOrcamento_id, vcg.Nome, vcg.CodVendedor_ID,
SUM(CASE WHEN ISNULL(vcg.Qt_SemReserv, 0) = 0 THEN 0 ELSE 1 END) AS QtdPend,
ROUND(SUM(vcg.Vl_SemReserv), 2) AS VlPend,
ROUND(((SUM(vcg.Vl_SemReserv) /@vlTotalPen)*100),8) AS Acumulado,
'' AS Acumulado2,
ROUND(SUM(vcg.Vl_Reserv + vcg.Vl_SemReserv), 2) AS VLTotal,
ROUND(((SUM(vcg.Vl_Reserv + vcg.Vl_SemReserv) /@vlTotal)*100),8) AS PercCartT,
SUM(CASE WHEN ISNULL(vcg.Qt_Reserv, 0) = 0 THEN 0 ELSE 1 END) AS QtdDisp,
COUNT(vcg.NITEM) AS ITENS
FROM Vw_CarteiraGer vcg
WHERE vcg.Empresa = '01' and vcg.Filial in (@Filial) AND vcg.FatParcial in (@Parcial)
GROUP BY vcg.Empresa, vcg.Filial, vcg.CodOrcamento_id, vcg.Nome, vcg.CodVendedor_ID
ORDER BY VlPend DESC

END

Qual dos dois exemplos estão certo??? E porque???

Exibições: 48

© 2017   Criado por Ramon Durães.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço