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.
| 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_idfrom tbl_deptwhere dept_id in (801,805,801,803,410,801)returnsSTATUS - DEPT_ID0 - 8011 - 8051 - 8030 - 410I 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 - 801Because 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 integerSTATUS 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" |
|
|
|
|
|