Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter results based on comparison with array of values

Status
Not open for further replies.

BradBooher

Technical User
Feb 9, 2009
1
I need to add a filter to my report results based on a multivalue parameter. I've tried writing it many ways but I'm thinking setting an IIF statement on the output field might be the best way? The filter has values all, viewed, emailed, printed, saved, and recommended. If the user chooses any values aside from all I only want results where the count on that field is > 0. Anyone have any suggestions?

Here is my sql query

WITH tmpContentviews AS
(
SELECT cvr.docname, Count(*) AS Views
FROM ContentViewRequest CVR
LEFT JOIN publishedcontent PC ON pc.docname = cvr.docname
WHERE CVR.CreatedOn >= @reportfrom AND CVR.CreatedOn <= @reportto
GROUP BY cvr.docname),
tmpContentPrints AS
(
SELECT cpr.printkey, Count(*) AS Prints
FROM PrintContent CPR
LEFT JOIN publishedcontent PC ON pc.docname = cpr.printkey
WHERE CPR.CreatedOn >= @reportfrom AND CPR.CreatedOn <= @reportto
GROUP BY cpr.printkey),
tmpContentSaves AS
(
SELECT prc.docname, Count(*) AS Saves
FROM ProjectContent PRC
LEFT JOIN publishedcontent PC ON pc.docname = prc.docname
WHERE PRC.CreatedOn >= @reportfrom AND PRC.CreatedOn <= @reportto
GROUP BY prc.docname),
tmpContentEmails AS
(
SELECT eaf.docname, Count(*) AS Emails
FROM EmailAFriend EAF
LEFT JOIN publishedcontent PC ON pc.docname = eaf.docname
WHERE EAF.CreatedOn >= @reportfrom AND EAF.CreatedOn <= @reportto
group by eaf.docname),
tmpcontentrecommendc AS
(
select cc.docname, count(*) as contactrecommend
from contentcontact CC LEFT JOIN
Publishedcontent PC ON pc.docname = cc.docname
where cc.createdon >= @reportfrom and cc.createdon <= @reportto
group by cc.docname),
tmpcontentrecommenda AS
(
select ca.docname, count(*) as accountrecommend
from contentaccount CA LEFT JOIN
Publishedcontent PC ON pc.docname = ca.docname
where ca.createdon >= @reportfrom and ca.createdon <= @reportto
group by ca.docname)
SELECT PC.DocName, PC.PublicationDate, PC.CreatedbyID, PC.Contenttypeid, CT.contenttypeID, C.contactname,
CT.contenttypename, tcv.views, tcs.saves, tcp.prints,
tce.emails, tcrc.contactrecommend, tcra.accountrecommend
FROM icoprod.publishedcontent PC LEFT OUTER JOIN
icoprod.contenttype CT ON PC.contenttypeID = CT.contenttypeId LEFT OUTER JOIN
icoprod.contact C ON PC.CreatedbyID = C.contactID LEFT OUTER JOIN
icoprod.account A ON C.accountID = A.accountid LEFT JOIN
tmpcontentviews tcv ON pc.docname = tcv.docname LEFT JOIN
tmpcontentprints tcp ON pc.docname = tcp.printkey LEFT JOIN
tmpcontentsaves tcs ON pc.docname = tcs.docname LEFT JOIN
tmpcontentemails tce ON pc.docname = tce.docname LEFT JOIN
tmpcontentrecommendc tcrc ON pc.docname = tcrc.docname LEFT JOIN
tmpcontentrecommenda tcra ON pc.docname = tcra.docname
WHERE (@contenttype = PC.contenttypeid OR @contenttype IS NULL) AND (@AccountType = '' OR A.AccountType IN (SELECT Value FROM Split(@AccountType,','))) AND A.deactivated = 'false'

For the output I think changing the docname expression will be the best option? I'm using the following but obviously it needs to be modified further

=IIF(InStr(JOIN(Parameters!contentusage.Value,","),"all"),Fields!DocName.Value,Fields!DocName.Value) Or IIF(InStr(JOIN(Parameters!contentusage.Value,","),"viewed"),Fields!DocName.Value where Fields!views.Value>0,Fields!DocName.Value)

Any suggestions or assistance is greatly appreciated!
Brad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top