I have a table :
id | Val
____________
1 | a
2 | s
3 | e
4 | f
5 | h
I have a query which accepts 2 params :
@id1 int
@id2 int
This query has 2 internal variables :
@val1 int
@val2 int
I need to set values into those variables : like –
select @val1=val from where id=@id1
select @val2=val from where id=@id2
I want to do it with one query…. I’ve tried:
select @val1=val , @val2=val
from table
where id=@id2 or id=@id1
The problem is :
@val1 should set to val only when id=@id1
and
@val2 should set to val only when id=@id2
(what about @val2 when id=@id1 ? what value will it get ?)
How can I write those 2 queries in 1 ?
To test it out: