Ylli Frroku
Ylli Frroku

Reputation: 19

SQL Filter rows if condition is true

I am trying to run a query that will filter the rows by this expression (If instance name LIKE '1 %' then remove all the rows that has the same EntityKeyID) I removed some columns on the example no place for them

    SELECT  
       EntityKeyID
      ,[StatusTypeID]
      ,[InternalNote]
      ,[InstanceName]
      ,[DateRequired]
      ,[LinkName]
      ,[VendorName]
  FROM [ASTRO].[dbo].[vw_EntityServices_Legs]
where  (SELECT statustypeID from vw_EntityServices_Legs where InstanceName LIKE '1 %') NOT IN InstanceName 

**Table that i want to create the query**

Upvotes: 0

Views: 429

Answers (1)

paparazzo
paparazzo

Reputation: 45096

Your words

If instance name LIKE '1 %' then remove all the rows that has the same EntityKeyID

where EntityKeyID not in ( select nl.EntityKeyID 
                           from vw_EntityServices_Legs nl 
                           where nl.InstanceName LIKE '1 %'
                         )

Upvotes: 1

Related Questions