May 7, 2008 at 2:22 am
Hi! There Please help with the query below, I would like to draw 12 months data using the query below please help.......
SELECT dbo.Clusters.Cluster, dbo.Consolidates.Consolidate, dbo.Level3.Level3, dbo.Divisions.Division, dbo.Regions.Region, dbo.Areas.Area,
dbo.Branches.Branch, dbo.Positions.Position, dbo.[Grade Grouping].[HC Cat1], dbo.Positions.BranchID, dbo.Staff.TransType, dbo.Positions.PosID,
dbo.Staff.STAFFNO
FROM dbo.Clusters INNER JOIN
dbo.Consolidates ON dbo.Clusters.ClusterID = dbo.Consolidates.ClusterID AND dbo.Clusters.Period = dbo.Consolidates.Period INNER JOIN
dbo.Level3 ON dbo.Consolidates.Period = dbo.Level3.Period AND dbo.Consolidates.ConsolidateID = dbo.Level3.ConsolidateID INNER JOIN
dbo.Divisions ON dbo.Level3.Level3ID = dbo.Divisions.Level3ID AND dbo.Level3.Period = dbo.Divisions.Period INNER JOIN
dbo.Regions ON dbo.Divisions.Period = dbo.Regions.Period AND dbo.Divisions.DivisionID = dbo.Regions.DivisionID INNER JOIN
dbo.Areas ON dbo.Regions.Period = dbo.Areas.Period AND dbo.Regions.RegionID = dbo.Areas.RegionID INNER JOIN
dbo.Branches ON dbo.Areas.Period = dbo.Branches.Period AND dbo.Areas.AreaID = dbo.Branches.AreaID INNER JOIN
dbo.Positions ON dbo.Branches.BranchID = dbo.Positions.BranchID AND dbo.Branches.Period = dbo.Positions.Period LEFT OUTER JOIN
dbo.Staff ON dbo.Positions.Period = dbo.Staff.Period AND dbo.Positions.PosID = dbo.Staff.PosID LEFT OUTER JOIN
dbo.[Grade Grouping] ON dbo.Staff.Grade = dbo.[Grade Grouping].GradeID
WHERE (dbo.Clusters.Cluster = 'Retail') AND (dbo.Positions.Period = 200803) AND (dbo.Positions.Deleted = 0)
May 9, 2008 at 11:56 am
It would seem to me that you mkust change:
AND (dbo.Positions.Period = 200803)
to
AND (dbo.Positions.Period between 200704 and 200803)
To "calculate" the starting period, you'ld have to cast this month into a date format, then use the datefunctions.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply