Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Selecting Multiple Values

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-05 : 23:53:35
Joe writes "I have a SQL question that is stumping me. I want to feed a list of values into a query and have it give me back the value in a column called STATUS for each value. Sounds easy enough. I figured if I used a query using IN that it would do the trick, but if the same value appears in the list more than once it is ignored, like when you use DISTINCT.

Example:
select status,dept_id
from tbl_dept
where dept_id in (801,805,801,803,410,801)

returns
STATUS - DEPT_ID
0 - 801
1 - 805
1 - 803
0 - 410

I need a query that would return each passed value and its status, even if the same value appears more than once in the list of values passed in the query.

- STATUS - DEPT_ID -
- 0 - 801
- 1 - 805
- 0 - 801
- 1 - 803
- 0 - 410
- 0 - 801

Because of the problem with IN I have to do a seperate query on each value and I don't want to do that if I can avoid it.

Layout of table:

DEPT_ID integer
STATUS integer (0 or 1, 0 = not active, 1 = active)

The resulting recordset will be processed by a program that looks to see if at least 3 of the values passed have a status of 1, even if all three are the same DEPT_ID.

Joe"
   

- Advertisement -