如果condition为true,则SQL Filter行

时间:2018-03-13 10:01:16

标签: sql sql-server sql-server-2012

我正在尝试运行一个查询,该查询将按此表达式过滤行(如果实例名称LIKE'1%'则删除所有具有相同EntityKeyID的行) 我在示例中删除了一些列没有它们的地方

    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**

1 个答案:

答案 0 :(得分:1)

你的话

  

如果实例名称LIKE' 1%'然后删除所有具有相同的行   EntityKeyID

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