检查数组的值是否在select语句中

时间:2015-04-17 22:09:34

标签: sql-server select notin

我有以下查询检查我的表中是否在数组中找不到AccountNumber的行:

--Select the total number of domestic keypad customers who left in march
select New_FirstName,New_LastName,New_AccountNumber,New_KeyPadPremiseNo ,New_DateCustomerLeft, c.Line1,c.Line2,c.Line3,c.City,c.PostOfficeBox from AccountExtensionBase as a
inner join CustomerAddressBase as c on a.AccountId = c.ParentId
where New_DateCustomerLeft between '1 feb 2015' and '1 mar 2015'
and AddressTypeCode = 1
and New_AccountType = 5
and New_AccountNumber not in (123,456,789,101112,131415)

如何检查我的数组是否包含数据库中找不到的数字,如:

select from ((123,456,789,101112,131415)
where not in (select from table)

1 个答案:

答案 0 :(得分:0)

除了将第一个列表放入临时表之外,您可以使用SQL(如果需要,可以使用excel公式快速创建一堆插入语句):

Select number from TempTable
except
Select number  from table

Select * from TempTable
where number not in (select number from table)