May 4, 2016 at 10:21 am
Hello,
Im new to sql and having a hard time creating a query which would provide me data which crosses two month. Table c.issuedate in some cases the data is dated 04012016 while all of the data from table a.app16_rvsd falls in between 03012016-03312016. How would I update the query below to incorporate the information which on table c.issuedate falls on 02/2016 or 04/2016. Thank you.
select distinct a.yyyymm,b.circuit,a.admin,a.unit,a.pas,a.ag,a.rcvddate, a.dispdate,C.issuedate, a.timely
from datamart.dbo.appl16_rvsd a,
datamart.dbo.distcoun b,
DATAMART.dbo.fsissue16 C
where a.county=b.county and a.yyyymm=b.yyyymm and A.ag=C.ag and a.yyyymm = '201603' and
substring(a.pas,1,1) <> 'E' and a.program='FS'
and a.type in ('I','R') and a.status='A'
and b.region='sc' and a.timestd=7
and a.district+a.admin not in ('0488151','2388198','1188101','1188102','0202555','0290132')
order by b.circuit,a.admin,a.unit,a.pas
May 4, 2016 at 11:00 am
If you're dealing with a star schema, you'd filter the Calendar/Date table and then the join would filter the Fact table.
SELECT ...
FROM FactTable f
INNER JOIN DimDate d
ON f.DateKey = d.DateKey
WHERE d.RealDate >= @StartDate AND d.RealDate<=@EndDate
May 4, 2016 at 12:46 pm
Note that, unless you ABSOLUTELY need it for some reason, you should get rid of that final ORDER BY statement. It will only slow down your query and does not change the results.
-- Itzik Ben-Gan 2001
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply