我确认SQL表中的列包含我要搜索的结果(结果为NA),但是当我使用下面的查询时,没有返回结果。 我可以帮忙吗?
SELECT DISTINCT *
FROM [DB_NAME].[dbo].[TABLE_NAME]
WHERE BECDescription like '%Time Warner%' AND
(CONCAT(PhysicalAddress1, PhysicalCity, PhysicalStateProvince) like ('%NA% %NA% %NA%')
) AND
PhysicalCountry like '%NA%' AND
CarrierName like '%NA%' AND
CurrNetChargeAmt = 1326.00
答案 0 :(得分:1)
我对您为什么在这里使用CONCAT()
感到有些困惑。这不是您想要的吗?
WHERE BECDescription like '%Time Warner%' AND
PhysicalAddress1 like '%NA%' AND
PhysicalCity like '%NA%' AND
PhysicalStateProvince like '%NA%' AND
PhysicalCountry like '%NA%' AND
CarrierName like '%NA%' AND
CurrNetChargeAmt = 1326.00
这当然更容易理解。
答案 1 :(得分:0)
您连接了PhysicalAddress1,PhysicalCity,PhysicalStateProvince,但在'%NA'之间添加了空格。
尝试
SELECT DISTINCT *
FROM [db_name].[dbo].[table_name]
WHERE BECDescription like '%Time Warner%' AND (CONCAT(PhysicalAddress1, ' ', PhysicalCity, ' ', PhysicalStateProvince) like ('%NA% %NA% %NA%')) AND PhysicalCountry like '%NA%' AND CarrierName like '%NA%' AND CurrNetChargeAmt = 1326.00