|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Immediate Help Needed
The requirement is something like this.I am using the stored procedure to develop the crystal report.
Requirement:check if current/today's date is in between startdate & enddate,if it is depending on the parameter(w-means current week, Y-means year to date,if parameter is blank then defaultly u need to display current week).I dont know how to map this parameter value w/ which column. we need to find the starting date of the week(first day of the week is monday & lastday of the week is sunday) & display the records for that particular week.if its yearly then its should diplay the data for that fiscal year(fiscal year starts from oct 1 to sep 30),eg we are now in nov,todays date is 18th when the parameter is Y then it should display the records from oct 1 to today's date. SELECT TaskOrder.CustomerCode, CustomerInfo.CustomerName, ModProjTaskDetail.DOLCode, TaskOrderAwards.PPStartDate, TaskOrderAwards.PPEndDate, ModProjTaskDetail.SkillCategory, COUNT(*) AS Plsmts_Total FROM TaskOrderAwardMods INNER JOIN TaskOrderAwards ON TaskOrderAwardMods.TaskOrderAwardNum = TaskOrderAwards.TaskOrderAwardNum INNER JOIN ModProjTaskDetail ON TaskOrderAwardMods.TaskOrderModNum = ModProjTaskDetail.TaskAwardModNum INNER JOIN TaskOrder ON TaskOrderAwards.TaskOrderNum = TaskOrder.TaskOrderNum INNER JOIN CustomerInfo ON TaskOrder.CustomerCode = CustomerInfo.CustomerCode WHERE (TaskOrderAwards.PPStartDate <= GETDATE()) AND (TaskOrderAwards.PPEndDate >= GETDATE()) GROUP BY TaskOrder.CustomerCode, CustomerInfo.CustomerName, ModProjTaskDetail.DOLCode, TaskOrderAwards.PPStartDate, TaskOrderAwards.PPEndDate, ModProjTaskDetail.SkillCategory |
|
#2
|
|||
|
|||
|
Not too hard, but...
You'll need to use some datetime manipulations. Remember, when you populate a datetime with a string and leave out the time part, you get a datetime of midnight at that date.
so for the weekly one, you'll want to do something like this: Code:
SET DATEFIRST 1 --First day of week now monday
Declare @StartDate datetime
IF @IntervalType = 'w'
BEGIN
Select @StartDate = convert(varchar(8), dateadd(day, -(datepart(dw, getdate())), getdate()), 112)
END
IF @IntervalType = 'Y'
BEGIN
Select @StartDate =
case when month(getdate()) >= 10 then '10/1/' + Year(getdate())
else '10/1/' + (Year(getdate()) - 1)
END
--Et cetera, with a new where clause that reflects this
Also, to set a default parameter in a sproc is easy. Just give it a value, like so: Code:
CREATE PROCEDURE usp_some_proc @IntervalType char(1) = 'w' as BEGIN ... to give the @IntervalType a default value of 'w'. Hope this helps, Steve Last edited by MrData : November 22nd, 2004 at 06:20 PM. Reason: screwed up the sproc declaration (no datatype) |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Immediate Help Needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|