I am running a query in SSRS that is using 2 common table expressions. The query runs fine in the query designer, but the when I press ok and the dataset is formed; the fields in the dataset are the columns in the select * statement inside the cte. How do I get the columns i created in the cte to show up in the fields of my dataset in the ssrs? Any help is much appreciated.
IF @FilterByEventCode IS NULL
BEGIN
SELECT *
FROM
dbo.Historywithqualityfilter(@FQN, '.Event Code,.Event Description',
Dateadd(mi, -10, @DateStart), @DateStop, 'good', 'KLN-FTVP')
END
ELSE
BEGIN
WITH t1(timestamp, eventcode)
AS (SELECT localtimestamp,
valueasstring
FROM dbo.Historywithqualityfilter (@FQN, '.Event Code',
Dateadd(mi, -10, @DateStart),
@DateStop, 'good', 'KLN-FTVP')
WHERE @FilterByEventCode = valueasstring),
t2(timestamp, eventdescription)
AS (SELECT localtimestamp,
valueasstring
FROM dbo.Historywithqualityfilter (@FQN, '.Event Description',
Dateadd(mi, -10, @DateStart), @DateStop, 'good',
'KLN-FTVP')
)
SELECT *
FROM t1 a
INNER JOIN t2 b
ON a.timestamp = b.timestamp
END