views:

27

answers:

3
id Ptypefield Value
1   1   D
2   1   E
3   1   F
4   1   G
5   1   H
6   2   FL
7   2   IF
8   2   VVS1
9   2   VVS2
10  2   VS1
11  2   VS2
12  3   0.50
13  3   1.00
14  3   1.50
15  3   2.00
16  4   Marquise
17  4   Round
18  4   Pear
19  4   Radiant
20  4   Princess

this table i want to get id no i give value like D and F

this is search so i give From D to F so in single query want to display D id value and F id value.

please write a query

+2  A: 
SELECT id FROM Table1 WHERE Value = "D" or Value = "F"
Lance Roberts
+1  A: 

Use the WHERE clause:

SELECT t.id
  FROM TABLE t 
 WHERE t.value IN ('D', 'F')

The IN clause is syntactic sugar, equivalent to:

SELECT t.id
  FROM TABLE t 
 WHERE t.value = 'D' OR t.value = 'F'
OMG Ponies
+1  A: 

If its a stored proc:

@value1 as varchar(50),
@value2 as varchar(50)

as
     begin
        select     t.id
        from       table t
        where      t.value in (@value1,@value2)
     end

you get the picture, you could use a bit of dynamic sql for the In clause if you wanted to have more values etc.

Darknight