Ho una query che utilizza una WHEREclausola e mi capita di usare la stessa identica WHEREclausola in molte query su questa tabella (et al).
La query è:
SELECT
DATENAME(DW, [AtDateTime]) AS [Day of Week]
,COUNT(*) AS [Number of Searches]
,CAST(CAST(COUNT(*) AS DECIMAL(10, 2))
/ COUNT(DISTINCT CONVERT(DATE, [AtDateTime])) AS DECIMAL(10, 2))
AS [Average Searches per Day]
,SUM(CASE WHEN [NumFound] = 0 THEN 1 ELSE 0 END)
AS [Number of Searches with no Results]
,CAST(CAST(SUM(CASE WHEN [NumFound] = 0 THEN 1 ELSE 0 END)
AS DECIMAL(10, 2)) / COUNT(*) AS DECIMAL(10, 4))
AS [Percent of Searches with no Results]
FROM [DB].[dbo].[SearchHistory]
WHERE
[CustomerNumber] <> '1234' AND [CustomerNumber] <> '5678'
GROUP BY DATENAME(DW, [AtDateTime]), DATEPART(DW, [AtDateTime])
ORDER BY DATEPART(DW, [AtDateTime])
La parte che desidero modificare è la WHEREclausola, per consentirmi invece di utilizzare una tabella in modo che se devo aggiungere un numero cliente per essere ignorato, non devo aggiornare tutte le mie query. (E ci sono alcune query che hanno questa stessa WHEREclausola.)