12,623,776 members (28,151 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
I have a table which has 2 columns namely PlanId and RiderId in below format-
Query is- I want pass multiple riderid and i want to get `PlanId` on the base of multiple `RiderId`.
In this case i will pass `327,329,330,326,355`.
But 327 available in 2 times in `PlanId` column having `356349` and `356347 `but here i want only one `PlanId` which is `356349` , because it hold combination values. How i accomplish this.

```PlanId	RiderId
===============
356348	330
356348	355
356348	327
356348	329
356349	327
356349	329
356349	330
356349	326
356349	355```
Posted 7-Feb-13 4:16am
Updated 11-Feb-13 0:58am
v2
Comments
skydger 7-Feb-13 9:48am

What query do you use?
Without knowing structure of your tables no one could help you. Please improve your question and tell a secret of your 'plans' table which holds relation to magic 'combination values'.
Sheikh Muhammad Haris 7-Feb-13 14:04pm

What is you Combination Value logic? Why do you want to select 356349 ?

## 2 solutions

Rate this:
Please Sign up or sign in to vote.

## Solution 1

Hi,

I think you want to use GROUPS, let's see if I understand:

```SELECT
YourTable.PlanId
,YourTable.RiderId
FROM
YourTable
GROUP BY
YourTable.PlanId,
YourTable.RiderId
HAVING
YourTable.RiderId IN (--your inputs here)
--Example:
--YourTable.RiderId IN (327,329,330,326,355)
```

Hope it helps
v2
Rate this:
Please Sign up or sign in to vote.

## Solution 2

Write stored procedure[^], like this:
```CREATE PROCEDURE GetPlanIDByRiderID
@riderids NVARCHAR(1000)
--example input: '321, 322, 333'
AS

SELECT PlanId, RiderId
FROM YourTable
WHERE RiderId IN (@riderids)
ORDER BY PlanId, RiderId

GO```

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 John Simmons / outlaw programmer 160 Peter Leow 115 ppolymorphe 107 OriginalGriff 85 Afzaal Ahmad Zeeshan 70
 OriginalGriff 1,007 ppolymorphe 489 John Simmons / outlaw programmer 449 CPallini 308 Peter Leow 255

Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100