rajborntodare (2/10/2014)
Hi I have a table (Billing Table) having multiple records forpeople having one record per person per each month.
how to get a list of the guys having record just for one month (say feb)
and doesn't have any other months.
please give an advise..
i think you also need to add a test for the other months with NOT EXISTS:
-- Created By: Lowell Izaguirre
-- Create Date: |CurrentDate|
-- Description:
-- Modified By: Lowell Izaguirre
-- Modified Date: |CurrentDate|
-- Description:
declare @StartDt DATE
declare @EndDtDATE
SET @StartDt = '2/1/2014'
SET @EndDt = '2/28/2014'
SELECT DISTINCT T1.YOURCUSTOMERID
,T1.YOURCUSTOMERNAME
FROMYOURTABLE T1
WHERET1.YOURDATECOLUMN BETWEEN @StartDt AND @EndDt
AND NOT EXISTS (SELECT 1
FROM YOURTABLE T2
WHERE T1.YOURCUSTOMERID = T2.YOURCUSTOMERID
AND (T2.YOURDATECOLUMN < @StartDt OR T2.YOURDATECOLUMN > @EndDt )
)
Lowell