Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Please help me My sql table look like this

Slno   HeadName    BankCode
1	Abc         Cash
2	Contra	   Bank1
3	Contra	   Cash
4	Xyz	   Cash
5	Contra	   Bank2
6	Contra	   Cash
7	Pqr	   Bank1


My requirement is to filter the table.i Need to remove the 'Contra' from HeadName and BankCode not equal='Cash' ie remove slno no 2,5 all other rows i would like to retrive all other rows

please help

My table structure and sample data is given below

SQL
CREATE TABLE [dbo].[sampletable2]( ID INT PRIMARY KEY , [HeadName] nvarchar, [BankCode] nvarchar )

Insert Into sampletable2 Values(1,'Abc','Cash'), Insert Into sampletable2 Values(2,'Contra','Bank1') Insert Into sampletable2 Values(3,'Contra','Cash') Insert Into sampletable2 Values(4,'Xyz','Cash') Insert Into sampletable2 Values(5,'Contra','Bank2') Insert Into sampletable2 Values(6,'Contra','Cash') Insert Into sampletable2 Values(7,'Pqr' ,'Bank1')

Select * from sampletable2
Posted
Updated 27-Aug-14 0:15am
v2

1 solution

Hi,

Try this...
SQL
--Final  

insert into sampletable2 
SELECT * from yourtable
where id not in (SELECT id from yourtable WHERE 
BankCode in ('Bank2','Bank1') and headName = 'Contra'
 )


Hope this will help you.


Cheers
 
Share this answer
 
v4
Comments
jinesh sam 27-Aug-14 5:41am    
Thanks Dear for your help.

Sorry your code doesn't full fill my requirement. please help

It will remove only 5th row. i need to remove 2nd row also
Magic Wonder 27-Aug-14 5:44am    
Missed that record, check edited version.
jinesh sam 27-Aug-14 5:52am    
again problem last row ie 7th record missing
dear my requirement is no 'Contra' From HeadName column and other condition is BanCode <>'Cash'
Magic Wonder 27-Aug-14 5:57am    
yes i edited....check ver 3
Magic Wonder 27-Aug-14 6:08am    
Check Final Version.

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