Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai friendz,
i written two sp's

one is for Selecting AdminId by EmployeeId

SQL
select AdminId from Employee where EmployeeId=@EmpId


another one is for Selecting CompanyName by AdminId
SQL
select E.CompanyId,C.CompanyName from Employee E,Company C where E.AdminId =@AdminId and E.CompanyId=C.Id 



i want to select CompanyName by AdminId where I am passing EmployeeId..so i written two sp's for that..

Is there any way to combine these two sp's..
I want to write these two in a single sp...

Please help me

Thanks in advance
Posted
Updated 14-Oct-12 23:28pm
v3

SQL
SELECT e.AdminId , s.CompanyName,s.CompanyId
   FROM Employee e
   INNER JOIN Company s
           ON e.AdminId = s.AdminId
  WHERE e.EmployeeId=@EmpId
 
Share this answer
 
Comments
.net333 15-Oct-12 4:53am    
Thank you so much vivek...It's working..i tried many ways..but i didn't get the output....Once again Thank you
vivektiwari97701 15-Oct-12 4:55am    
dont forgot to mark as solution.:-)
SELECT e.AdminId , s.CompanyName,s.CompanyId
FROM Employee e
INNER JOIN Company s
ON e.AdminId = s.AdminId
WHERE e.EmployeeId=@EmpId and E.AdminId =@AdminId
 
Share this answer
 
Comments
.net333 15-Oct-12 5:26am    
thank you..here i am not passing the AdminId..and i got the solution
SELECT e.AdminId , s.CompanyName,s.CompanyId
FROM Employee e
INNER JOIN Company s
ON e.AdminId = s.AdminId
WHERE e.EmployeeId=@EmpId
bhargavpp 15-Oct-12 5:34am    
please vote it..
u can use if condition i your Sp


SQL
IF condition 
(statement)
Else 'if insert returns an error'
( statement)
end
 
Share this answer
 
Comments
.net333 15-Oct-12 4:40am    
thank you..but here i want to execute two queries...only i am passing EmployeeId from UI...by using EmployeeId i will get AdminId..By Using AdminId i will get CompanyName...
vivektiwari97701 15-Oct-12 4:42am    
then u can use inner join.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900