Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :setvar cliente FundacaoLemann4600Tests
- /****** Object: StoredProcedure [dbo].[SpVisaoHistorica] Script Date: 19/06/2017 18:40:11 ******/ DW-FundacaoLemann4600Tests
- use [DW-$(cliente)]
- create Procedure Sp_ListaMembrosPermissoes (
- @idMatriz int, -- 18
- @idDimX varchar(4), --2047
- @idDimY varchar(4), --2050
- @idDimz varchar(4), --2048
- @idVisao int, --27
- @IdColaborador int -- 1
- )
- as begin
- /* Created Paulo Henrique Patrício */
- /* Construção do filtro Membros no Where */
- declare @membros varchar(400)
- /* Preenchimento de @iddimx e @iddimy obrigatórios apenas @iddimz opcional */
- if (@idDimX <> '' or @idDimX is null) and (@idDimY <> '' or @idDimY is null) and (@idDimz <> '' or @idDimz is null)
- begin
- set @membros = ' IdDimensao in (' + @idDimX + ',' + @idDimY + ',' + @idDimz + ')'
- end
- if (@idDimX <> '' or @idDimX is null) and (@idDimY <> '' or @idDimY is null) and (@idDimz = '')
- begin
- set @membros = ' IdDimensao in (' + @idDimX + ',' + @idDimY +') '
- end
- declare @sql varchar(max)
- if object_id('tempdb..##temppermissoes') is not null drop table ##temppermissoes
- set @sql = '
- /* neste cenário, nós temos exatamente os membros que o colaborador possui acesso */
- select
- m.idEixoXYZ
- ,m.Codigo
- ,m.Nome
- ,m.IdDimensao
- ,m.idParent
- ,m.TipoComponente
- into ##temppermissoes from DimEixoXYZ as m where idEixoXYZ in
- (
- select IdMembroDimensao
- from PermissaoFinanceira as p
- where
- IdMatriz = 18 -- = @idMatriz
- and ' + @membros + '
- and IdColaborador = 1 -- =@idColaborador
- and idVisao = 27 -- =@idVisao
- )
- /* Querry recursiva para retornar os membros e os parents cujo o usuário possui acesso */
- ;WITH cteMenuNivel(
- Nivel,
- idEixoXYZ
- ,Codigo
- ,Nome
- ,IdDimensao
- ,idParent
- ,TipoComponente)
- AS
- (
- -- Ancora
- select
- 1 as Nivel
- ,m.idEixoXYZ
- ,m.Codigo
- ,m.Nome
- ,m.IdDimensao
- ,m.idParent
- ,m.TipoComponente
- from ##temppermissoes as m
- --where idParent is null
- union ALL
- -- Recursivo
- select
- Nivel + 1 as Nivel
- ,p.idEixoXYZ
- ,p.Codigo
- ,p.Nome
- ,p.IdDimensao
- ,p.idParent
- ,p.TipoComponente from DimEixoXYZ p
- INNER JOIN cteMenuNivel as c ON c.idParent = p.idEixoXYZ
- )
- select
- idEixoXYZ
- ,Nome
- ,Codigo
- ,IdDimensao
- ,TipoComponente
- ,0 as Checked
- ,idParent from ctemenunivel
- order by IdDimensao asc, idParent asc
- '
- exec (@sql)
- end
Advertisement
Add Comment
Please, Sign In to add comment