0

을 기준으로보고되었습니다. SQL Server 2008 R2 (Visual Studio 환경)에서 SSRS를 사용합니다.SSRS 계단식 번호는

SQL Server의 테이블에서 수준/값을 기반으로 한 단계적 보고서를 작성하려고합니다. sort_value가있는 들여 쓰기 위치의 수준 동작은 보고서에서 재귀 부모입니다. SQL Server의 테이블의

샘플 : 출력의

Sample table View

샘플

Sample Report output view

+0

귀하의 문제는 탭 및 부속품이 모두 제품이라는 점입니다. 이렇게하면이 방법으로 분할 할 수 없습니다. – Snowlockk

+0

테이블의 실제 데이터 형식 또는 다른 쿼리 결과입니다. 다른 쿼리의 결과 인 경우 원시 데이터 샘플을 게시 할 수 있습니까? 당신이하려고하는 것은 가능하다고 생각합니다. 우리가 구조화 된 데이터가 더 좋다면 훨씬 쉽습니다. –

답변

0

확인을 요구, 나는 해결책을 마련했지만 를 다음 사항에 유의하시기 바랍니다 계속하기 전에. 1. 프로세스는 샘플 데이터에 따라 올바른 순서로 데이터를 사용합니다. 2. 이것이 실제 데이터 구조 인 경우 검토하는 것이 좋습니다.

좋아, 그래서 내가했던 첫 번째 일은 정확히 예제에 따라 테이블을 다시 만들었습니다. 나는 다른 것을 생각할 수 없어서 테이블 Stepped를 불렀다!

다음 코드는 SSRS에서 데이터 집합으로 사용할 수 있지만 출력을 보려면 T-SQL을 직접 실행할 수 있습니다. 출력은 다음과 같습니다

-- Create a copy of the data with a row number. This means the input data MUST be in the correct order. 
DECLARE @t TABLE(RowN int IDENTITY(1,1), Sort_Order int, [Level] int, Qty int, Currency varchar(20), Product varchar(20)) 

INSERT INTO @t (Sort_Order, [Level], Qty, Currency, Product) 
    SELECT * FROM Stepped 

-- Update the table so each row where the sort_order is NULL will take the sort order from the row above 
UPDATE a SET Sort_Order = b.Sort_Order 
FROM @t a 
    JOIN @t b on a.RowN = b.rowN+1 
WHERE a.Sort_Order is null and b.Sort_Order is not null 

-- repeat this until we're done. 
WHILE @@ROWCOUNT >0 
    BEGIN 
     UPDATE a SET Sort_Order = b.Sort_Order 
      FROM @t a 
       JOIN @t b on a.RowN = b.rowN+1 
      WHERE a.Sort_Order is null and b.Sort_Order is not null 
    END 

-- Now we can select from our new table sorted by both sort oder and level. 
-- We also separate out the products based on their level. 
SELECT 
     CASE Level WHEN 1 THEN Product ELSE NULL END as ProdLvl_1 
     , CASE Level WHEN 2 THEN Product ELSE NULL END as ProdLvl_2 
     , CASE Level WHEN 3 THEN Product ELSE NULL END as ProdLvl_3 
     , QTY 
     , Currency 
    FROM @t s 
    ORDER BY Sort_Order, Level 

...

enter image description here

당신은이에 대한 마지막 문을 교환하는 것이 좋습니다.

-- Alternatively use this style and use a single column in the report. 
-- This is better if the number of levels can change. 
SELECT 
     REPLICATE('--', Level-1) + Product as Product 
     , QTY 
     , Currency 
    FROM @t s 
    ORDER BY Sort_Order, Level 

이렇게하면 '제품'에 대한 열이 다음과 같이 들여 쓰기됩니다. enter image description here