我有一张显示人口信息的人口统计详细信息表。字段是
我需要有报告以下列格式显示人口详细信息
India Current Yr Figure PreviousYr Figure
State_1 X,XX,XX,XXX XX,XX,XXX
State_2 X,XX,XX,XXX XX,XX,XXX
State_3 X,XX,XX,XXX XX,XX,XXX
我尝试过以下查询:
WITH cte AS (
SELECT TOP (99.99) PERCENT
Population, City, State, SurveyDate, Region, Country,
CASE WHEN (DATEPART(yyyy, surveydate) = DATEPART(yyyy, GETDATE()))THEN 'CurrentYear' ELSE NULL END AS CurrentYear,
CASE WHEN (DATEPART(yyyy, surveydate) <> DATEPART(yyyy, GETDATE())) THEN 'LastYear' ELSE NULL END AS LastYear
FROM DemographicDetails
ORDER BY City)
SELECT Population, City, State, Region, Country, SurveyDate,
CurrentYear, LastYear, COALESCE (CurrentYear, LastYear) AS DateStatus
FROM cte AS cte_1
在报告文本框中,我将表达式表示为:
iif(Fields!DateStatus.Value="CurrentYear",Fields!Population.Value,0)
在第一个文本框和第二个框中,表达式为:
iif(Fields!DateStatus.Value="LastYear",Fields!Population.Value,0)
但是,我的结果与此类似:
India Current Yr Figure PreviousYr Figure
State_1 value1 0
State_1 0 value2
State_2 value3 0
State_3 value4 0
但我需要如下:
India Current Yr Figure PreviousYr Figure
State_1 value1 value2
State_2 value3 0
State_3 value4 0
,即同一行中的state_1 value1和value2。