SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSRS - Multi values parameters - display records exclusively


SSRS - Multi values parameters - display records exclusively

Author
Message
jack.yin 56852
jack.yin 56852
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 6
Hi everyone,
I have a unique request from a customer, I am even having trouble to word it out in the subject. Anyway, I will try explain here and any insight is greatly appreciated.

Imaging I have the following records

Name Skills
John A .Net
John A C#
Jane C#
Robert BA

So on the report, the customer wants to see a list of people with selected skills. I used a multiple values parameter, Skill, with the options of .Net, C# and BA. Typically, if I select .Net and C#, It will return:
John A
Jane

What the customer really wants is to return people with both skills, not either skill. (it's AND operator, not OR), really it should only return:
John A

I don't think that's what multiple values parameter is meant to be, but any solution/insight/work-around is greatly welcomed.

Thanks!

Jack
pietlinden
pietlinden
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52588 Visits: 16776
I'm working on it... In T-SQL, it would be like this:
(Yes, I'm aware that this table design of Candidate is silly!!!)
.
CREATE TABLE Candidate(
CandidateID INT IDENTITY,
FirstName VARCHAR(15) NOT NULL
CONSTRAINT pkCandidate PRIMARY KEY (CandidateID),
CONSTRAINT uqFirstName UNIQUE (FirstName));
GO
CREATE TABLE CandidateSkills(
SCandidateID INT,
Skill VARCHAR(10)
CONSTRAINT pkCS PRIMARY KEY (ScandidateID, Skill),
CONSTRAINT fkCandidate FOREIGN KEY (SCandidateID) REFERENCES Candidate(CandidateID));
GO

Now add some records
INSERT INTO Candidate(FirstName) VALUES ('John'),('Jane'),('Robert');

INSERT INTO CandidateSkills(SCandidateID,Skill)
VALUES (1,'.Net'),(1,'C#'),(2,'C#'),(3,'BA');
;

T-SQL Answer... well, a start...
DECLARE @Skill1 VARCHAR(10) = 'C#',
@Skill2 VARCHAR(10) = '.Net';
SELECT *
FROM Candidate c
WHERE EXISTS (
SELECT 1
FROM CandidateSkills cs
WHERE cs.SCandidateID = c.CandidateID
AND cs.Skill= @Skill1 )
AND EXISTS (
SELECT 1
FROM CandidateSkills cs
WHERE cs.SCandidateID = c.CandidateID
AND cs.Skill=@Skill2 )


This does the ANDing of the filters (unlike the OR that IN() does.)

Not sure how to do the ANDing from SSRS....
pietlinden
pietlinden
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52588 Visits: 16776
Jack,
I asked a question about how to do this in another forum. Check this out:
https://www.sqlservercentral.com/Forums/1922517/EXISTS-ALL#bm1922645
jack.yin 56852
jack.yin 56852
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 6
Thanks both for prompt response!
It's truly helpful.
pietlinden
pietlinden
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52588 Visits: 16776
Jack,
Luis' answer fixed it. This is the query I ended up using that worked for me:
SELECT    candidate_id, first_name, last_name
FROM Candidate AS c
WHERE (NOT EXISTS
(SELECT 1 AS Expr1
FROM Candidate AS ci CROSS JOIN
Skill AS s LEFT OUTER JOIN
CandidateSkills AS cs ON ci.candidate_id = cs.candidate_id AND s.skill_id = cs.skill_id
WHERE (cs.candidate_id IS NULL) AND (ci.candidate_id = c.candidate_id) AND (s.skill_id IN (@prmSkills))))


I created a multi-valued parameter which used a dataset of Skills (SkillID, SkillName). Then I could select the group of skills I am looking for and return only the candidates with them all.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search