Tbn779
Tbn779

Reputation: 73

SQL Server : how to delete specific rows data with where condition in column?

I have a table with some columns and rows. I want to delete some rows contain specific data at specific row.

Ex: the table name is EXAM

enter image description here

I want to delete row 1 and row 3 when input condition string is C.

I did with the statement:

DELETE FROM EXAM 
WHERE Comumn2 = 'C' 

but only deleted Row 3.

Upvotes: 4

Views: 21252

Answers (2)

Pரதீப்
Pரதீப்

Reputation: 93694

Another Way of doing it by using CharIndex

DELETE FROM EXAM WHERE CHARINDEX('C',Column2)>0

Upvotes: 0

sgeddes
sgeddes

Reputation: 62831

To match rows which contain a specific value, use LIKE instead of =:

DELETE FROM EXAM WHERE Column2 LIKE '%C%'

Upvotes: 8

Related Questions