February 10, 2014 at 2:42 pm
Hi I have a table (Billing Table) having multiple records for
people 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..
February 10, 2014 at 2:50 pm
declare @StartDt DATE
declare @EndDtDATE
SET @StartDt = '2/1/2014'
SET @EndDt = '2/28/2014'
SELECT DISTINCT YOURCUSTOMERID
,YOURCUSTOMERNAME
FROMYOURTABLE
WHEREYOURDATECOLUMN BETWEEN @StartDt AND @EndDt
February 10, 2014 at 2:58 pm
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
February 10, 2014 at 4:26 pm
Appreciate your help
But their is another problem
where there can be also a customer who is having bill in both jan, feb may be all months
but I want them who have only in jan
February 10, 2014 at 5:08 pm
Thats where the NOT EXISTS comes into play which Lowell posted. If any of your customers have records outside the range they will be elminated from the results.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply