Click here to Skip to main content
15,886,831 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to fetch some value from a table but i am comparing with another column of a table.

SQL
alter   PROCEDURE [dbo].[FMS_findteacherbysubject]
@sub nvarchar(50)
as

begin
if not exists (select l.StaffName,l.TeachingSubject from LeaveDetails l,StaffDetails s where s.StaffName=l.StaffName)
 begin
select s.StaffName,s.Qualification,s.Experience from StaffDetails s
 where s.Subject='@sub'
 end
 end


Table 1.

VB
StaffName  id Subject from      to
Ashraf Ali 1 Maths 2013-12-02   2013-12-20


</pre>

VB
Table 2
        StaffName        Quali Exp     Subject 
8	Ashraf Ali	M-Tech	2Year	Maths	
9	Jawed	        BBA	1Year	Physics	
10	Amar	        BA	1Year	Physics	
11	Saurabh	       B-Tech	5Year	Maths	
7	Rohit Sharma	B-Tech	1Year	Biology	
</pre>
Posted
Updated 7-Dec-13 0:37am
v2
Comments
bbirajdar 7-Dec-13 6:33am    
use sql join
joginder-banger 7-Dec-13 13:18pm    
use the Inner join before joining start put the primary key and foreign key.

1 solution

I got the Query

SQL
ALTER procedure [dbo].[FMS_findstaff]
@sub nvarchar(50)
as
select StaffName from StaffDetails where Subject=@sub
except
select StaffName from LeaveDetails
 
Share this answer
 

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