In a stored procedure, how to execute a request and conditionally do something

How to do this in a stored procedure (SQL 2005):

count = select count(*) from table1 where line like '%success%'
if count > 0:
   delete from table1 where not line like '%success%'

Thanks for any help. My google skills really fail today: - (

+3
source share
3 answers

So, if there are lines in which linelike success, then delete any lines where you linedo not like success?

IF EXISTS (SELECT * from table1 where line like '%success%')
   delete from table1 where line NOT like '%success%'
+5
source

I would write that in this way

if exist (select 1 from table1 where line like '%success%')
begin
    delete from table1 where line not like '%success%'
end
+5
source

. ?

where.

+1

Source: https://habr.com/ru/post/1744946/


All Articles