Saturday, February 25, 2012

Conditional Filtering in Reporting Services

I am using the following SQL query in a SSRS 2005 report (see below).
I need dbo.FilteredNew_Assets.new_assettypename = "Computer" ONLY when
the value of dbo.FilteredNew_Assets.new_assignedemployeeid is NOT
null. In other words, only when
dbo.FilteredNew_Assets.new_assignedemployeeid has a value do I need
dbo.FilteredNew_Assets.new_assettypename to be filtered.
Is this a task that needs to be accomplished within my SQL query or
somewhere within the context of the actual report? Either way, how do
I accomplish this?
SELECT dbo.FilteredNew_Employee.new_employeeid,
dbo.FilteredNew_Assets.new_assignedemployeeid,
dbo.FilteredNew_Employee.new_employeetypename,
dbo.FilteredNew_Employee.new_firstname,
dbo.FilteredNew_Employee.new_lastname,
dbo.FilteredNew_Assets.new_assettypename,
dbo.FilteredNew_Assets.new_computertypename,
dbo.FilteredNew_Assets.new_manufacturer,
dbo.FilteredNew_Assets.new_model,
dbo.FilteredNew_Assets.new_modelnumber,
dbo.FilteredNew_Assets.new_assetsid,
dbo.FilteredNew_Assets.new_name
FROM dbo.FilteredNew_Employee LEFT OUTER JOIN
dbo.FilteredNew_Assets ON
dbo.FilteredNew_Employee.new_employeeid = dbo.FilteredNew_Assets.new_assignedemployeeid
ORDER BY dbo.FilteredNew_Employee.new_lastnamePut filterednew_assets into a derived table like this and you=B4re able
to link on this derived table.
The union all reunites both sets of data, one set containing specific
conditional filter
SELECT *
FROM dbo.FilteredNew_Employee LEFT OUTER JOIN
(
SELECT
FNA.new_assignedemployeeid,
FNA.new_assettypename,
FNA.new_computertypename,
FNA.new_manufacturer,
FNA.new_model,
FNA.new_modelnumber,
FNA.new_assetsid
FROM dbo.FilteredNew_Assets FNA
WHERE FNA.new_assignedemployeeid IS NOT NULL And
FNA.New_assettypename =3D "Computer"
UNION ALL
SELECT
FNA.new_assignedemployeeid,
FNA.new_assettypename,
FNA.new_computertypename,
FNA.new_manufacturer,
FNA.new_model,
FNA.new_modelnumber,
FNA.new_assetsid
FROM dbo.FilteredNew_Assets FNA
WHERE FNA.new_assignedemployeeid IS NULL
) DerivedNewAssets ON dbo.FilteredNew_Employee.new_employeeid =3D
DerivedNewAssets.new_assignedemployeeid

No comments:

Post a Comment