Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello sir,
i wrote this procedure for geeting one week data from database (monday to saturday)
and i want to write storedprocedure for get 3 weeks data from database
but i have no idea how to write
please check my sp and give me solution
thanks in advance
C#
--exec [GetStudentCourseWiseBookingReport] '2010-09-08'
ALTER PROCEDURE [dbo].[GetStudentCourseWiseBookingReport]
@UserDate datetime
AS
BEGIN
DECLARE @StartDate	AS DATETIME
DECLARE @EndDate AS DATETIME
	
	set @StartDate=CONVERT(DATETIME,DATEADD(wk,DATEDIFF(wk,0,@UserDate),0))
	set @EndDate=CONVERT(DATETIME,DATEADD(wk,DATEDIFF(wk,0,@UserDate),5))
	
	select CourseName,count(CourseName)course_count,StartDate as DB_StartDate,@StartDate as Week_StartDate , @EndDate AS Week_EndDate
	from GL_BookingList bl
		inner join GL_MasterPriceDefaultSelection mpds on bl.PriceItemId=mpds.PriceItemId 
		inner join GL_Course on GL_Course.CourseID= mpds.SelectionId			  
		where GL_Course.StartDate between @StartDate and @EndDate
		group by CourseName,StartDate	
	
END	
Posted

How about:
SQL
select contentID, title, created 
from content
where created < dateadd(week,-3,getdate());

This sticks closer to the question. 21 days is fine, obviously means the same, but I find that it's good to use the terminology used in the question.
For example... a while back I was asked to survey an average of 1 in 50 visitors to a site. I described this as a proportion of 0.02, and the client wasn't happy. I pointed out to the client that they're the same, but I learned my lesson, and now if I change the way that something is described, I make sure I comment to that effect, and preferably don't change it in the first place. If the client wants 3 weeks, do it as 3 weeks, not 21 days.
 
Share this answer
 
Comments
Manish Dalwadi 17-Oct-14 6:59am    
my dear,
i want data in this format
coursename, firstweekdata secondweekdata thisrdweekdata
---------- ------------- -------------- --------------
c language 3 5 10

this digits are count of coursename
manish350 wrote (in comment):
my dear,
i want data in this format
coursename,  firstweekdata secondweekdata thirdweekdata
c language       3             5               10

this digits are count of coursename



Pivot query[^] may help.

SQL
SELECT coursename, [1], [2], [3]
FROM (
    SELECT coursename, DATEDIFF(WK, StartDate, @userdate)
    FROM ...
) AS DT
PIVOT(COUNT(coursename) FOR coursename IN ([1], [2], [3])) AS PT
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900