Click here to Skip to main content
15,892,072 members
Home / Discussions / Database
   

Database

 
GeneralRe: Getting underlying table-column value from a selected DataGridRow Pin
Mycroft Holmes12-Jan-10 14:00
professionalMycroft Holmes12-Jan-10 14:00 
QuestionSelecting Rows Pin
sriharsha_1210-Jan-10 19:32
sriharsha_1210-Jan-10 19:32 
AnswerRe: Selecting Rows PinPopular
Mycroft Holmes10-Jan-10 20:59
professionalMycroft Holmes10-Jan-10 20:59 
GeneralRe: Selecting Rows Pin
sriharsha_1210-Jan-10 23:08
sriharsha_1210-Jan-10 23:08 
QuestionOracle Pin
MsmVc10-Jan-10 17:14
MsmVc10-Jan-10 17:14 
AnswerRe: Oracle Pin
Mycroft Holmes10-Jan-10 18:15
professionalMycroft Holmes10-Jan-10 18:15 
AnswerRe: Oracle Pin
Jörgen Andersson10-Jan-10 21:56
professionalJörgen Andersson10-Jan-10 21:56 
Questionget list of weeks with week number Pin
Maddie from Dartford10-Jan-10 5:08
Maddie from Dartford10-Jan-10 5:08 
Hello,
I want to write a stored procedure in SQL wich returns last 12 weeks list (including current week) with start date.
e.g.
01: 04 Jan 10
53: 28 Dec 09
52: 21 Dec 09
51: 14 Dec 09
:
:

P.S. My first day of week is Monday so first week of year 2010 will start from 4 Jan 2010 and week starting from 28 Dec will be wk 53.

I am doing something like this

ALTER PROCEDURE [dbo].[GetWeekNumberList]
@IncludeCurrentWeek BIT = NULL

AS
BEGIN
SET DATEFIRST 1;
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
    -- Insert statements for procedure here
	CREATE TABLE #tempWeekList(weekDate DATETIME, weekLabel VARCHAR(25))

	DECLARE @Counter INT,
		@StartDate DATETIME,
		@EndDate DATETIME


	IF @IncludeCurrentWeek IS NOT NULL AND @IncludeCurrentWeek = 1
		BEGIN
			SET @StartDate = DATEADD(dd, (DATEPART(dw, GETDATE()) * -1) + 1, GETDATE())
		END
	ELSE
		BEGIN
			SET @StartDate = DATEADD(dd, (DATEPART(dw, DATEADD(dd, -7, GETDATE())) * -1) + 1, DATEADD(dd, -7, GETDATE()))
		END
	SET @EndDate = DATEADD(dd, 4, @StartDate)
	SET @Counter = 1
	

	WHILE @Counter <= 12
	BEGIN
		INSERT INTO #tempWeekList
		VALUES (@EndDate, CAST(DATEPART(wk, @EndDate) AS VARCHAR) + ': ' + CONVERT(VARCHAR, @StartDate, 6))
		SET @StartDate = DATEADD(dd, -7, @StartDate)
		SET @EndDate = DATEADD(dd, 4, @StartDate)
		SET @Counter = @Counter + 1
	END

	SELECT * FROM #tempWeekList

	DROP TABLE #tempWeekList
END


I am not able to get the 53 as last week. How to do it?
Any idea or help will be very useful to me.

Thanks.
AnswerRe: get list of weeks with week number Pin
Herman<T>.Instance13-Jan-10 3:53
Herman<T>.Instance13-Jan-10 3:53 
QuestionProblem with subquery returning more than 1 value [Solved] Pin
James Shao10-Jan-10 4:34
James Shao10-Jan-10 4:34 
AnswerRe: Problem with subquery returning more than 1 value Pin
dan!sh 10-Jan-10 4:50
professional dan!sh 10-Jan-10 4:50 
GeneralRe: Problem with subquery returning more than 1 value Pin
James Shao10-Jan-10 15:05
James Shao10-Jan-10 15:05 
AnswerRe: Problem with subquery returning more than 1 value Pin
Ashfield10-Jan-10 5:37
Ashfield10-Jan-10 5:37 
GeneralRe: Problem with subquery returning more than 1 value Pin
James Shao10-Jan-10 12:21
James Shao10-Jan-10 12:21 
GeneralRe: Problem with subquery returning more than 1 value Pin
dxlee10-Jan-10 15:34
dxlee10-Jan-10 15:34 
GeneralRe: Problem with subquery returning more than 1 value Pin
James Shao11-Jan-10 4:43
James Shao11-Jan-10 4:43 
GeneralRe: Problem with subquery returning more than 1 value Pin
dxlee11-Jan-10 6:48
dxlee11-Jan-10 6:48 
GeneralRe: Problem with subquery returning more than 1 value Pin
dan!sh 11-Jan-10 3:40
professional dan!sh 11-Jan-10 3:40 
GeneralRe: Problem with subquery returning more than 1 value Pin
James Shao11-Jan-10 4:36
James Shao11-Jan-10 4:36 
AnswerRe: Problem with subquery returning more than 1 value Pin
Corporal Agarn11-Jan-10 0:58
professionalCorporal Agarn11-Jan-10 0:58 
GeneralRe: Problem with subquery returning more than 1 value Pin
James Shao11-Jan-10 4:33
James Shao11-Jan-10 4:33 
Questionhow to get table names in MS Access database [Solved] Pin
K V Sekhar9-Jan-10 6:15
K V Sekhar9-Jan-10 6:15 
AnswerRe: how to get table names in MS Access database[ .mdb] Pin
Eddy Vluggen9-Jan-10 6:54
professionalEddy Vluggen9-Jan-10 6:54 
GeneralRe: how to get table names in MS Access database[ .mdb] Pin
K V Sekhar9-Jan-10 19:04
K V Sekhar9-Jan-10 19:04 
GeneralRe: how to get table names in MS Access database[ .mdb] Pin
Eddy Vluggen9-Jan-10 23:40
professionalEddy Vluggen9-Jan-10 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.