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
 General SQL Server Forums
 New to SQL Server Programming
 Giving where clause for subquery

Author  Topic 

callinnn
Starting Member

7 Posts

Posted - 2007-06-25 : 07:42:52
Hi all,

select u_emp,(select name from [@emp] where code=u_emp) name1
from ovpm
This query gives me the output having employee code and name.
I want to further filter the employee name by giving a where clause as
where name1='Carell'

Is it possible?
Please Help

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-25 : 07:55:27
Yes and I would rather prefer JOIN over Subquery:

select o.u_emp, e.name 
from ovpm o JOIN [@emp] e on e.code = o.u_emp
where e.name = 'Carell'



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-25 : 08:51:55
quote:
Originally posted by callinnn

Hi all,

select u_emp,(select name from [@emp] where code=u_emp) name1
from ovpm
This query gives me the output having employee code and name.
I want to further filter the employee name by giving a where clause as
where name1='Carell'

Is it possible?
Please Help


You should use JOIN as suggested. Otherwise your query will lead to error if subquery returns more than one value

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -