Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 tables named as T1 &T2 and these have some records
SQL
T1                     
-----                  
empno empname         
--------- ------------        
1      X              
2      y      
T2
-----
empno   empname
 --------- ------------
1        z
2        X       

THESE ARE THE RECORDS, NOW I WANT TO CHECK T1.empname=T2.empname if it true i want to delete that record from T2 else display all values from T2
Posted
Updated 13-Mar-13 18:09pm
v3
Comments
Davidduraisamy 14-Mar-13 0:11am    
Let me know whether my solution is ok for you or not

Use this:


SQL
if exists(select 1 from table1 a inner join table2 b on b.S_no=a.sl_no)
delete a from table1 a inner join table2 b on b.S_no=a.sl_no
else
select * from table2  
 
Share this answer
 
v3
Running a loop[^] on these tables along with the IF-ELSE statement[^] will help you achieve a solution.
 
Share this answer
 
1.
SQL
create procedure DeleteEntry
as
delete a from products1 a
inner join products b on a.productname=b.productname
go



try this i have tested.

[Edit]
2. (Added from another answer box)
SQL
alter procedure DeleteEntry
as
begin
delete a from products1 a
inner join products b on a.productname=b.productname
end
select * from products1
go



now try this..

[/Edit]
 
Share this answer
 
v2
Comments
Davidduraisamy 14-Mar-13 0:45am    
Raju he told thet,If it is equal then delete else select..you did only delete.

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