Click here to Skip to main content
15,903,203 members
Home / Discussions / Database
   

Database

 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
Covean29-Oct-09 2:04
Covean29-Oct-09 2:04 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
Mycroft Holmes29-Oct-09 2:06
professionalMycroft Holmes29-Oct-09 2:06 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 2:18
nainakarri29-Oct-09 2:18 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
Mycroft Holmes29-Oct-09 2:24
professionalMycroft Holmes29-Oct-09 2:24 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 2:35
nainakarri29-Oct-09 2:35 
AnswerRe: Problem with Execute query by EXEC(@string) Pin
soni uma29-Oct-09 2:44
soni uma29-Oct-09 2:44 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 2:47
nainakarri29-Oct-09 2:47 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
Abhishek Sur29-Oct-09 11:58
professionalAbhishek Sur29-Oct-09 11:58 
GeneralRe: Problem with Execute query by EXEC(@string) Pin
nainakarri29-Oct-09 18:34
nainakarri29-Oct-09 18:34 
AnswerRe: Problem with Execute query by EXEC(@string) Pin
NIRMAL UPADHYAY30-Oct-09 20:04
NIRMAL UPADHYAY30-Oct-09 20:04 
Questionhow to get week number and startday of the week in sql server 2008 Pin
chakran28-Oct-09 23:40
chakran28-Oct-09 23:40 
AnswerRe: how to get week number and startday of the week in sql server 2008 Pin
Mycroft Holmes29-Oct-09 0:33
professionalMycroft Holmes29-Oct-09 0:33 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
chakran29-Oct-09 0:45
chakran29-Oct-09 0:45 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
Mycroft Holmes29-Oct-09 2:03
professionalMycroft Holmes29-Oct-09 2:03 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
chakran30-Oct-09 1:09
chakran30-Oct-09 1:09 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
Niladri_Biswas30-Oct-09 1:45
Niladri_Biswas30-Oct-09 1:45 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
chakran30-Oct-09 2:20
chakran30-Oct-09 2:20 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
Niladri_Biswas30-Oct-09 3:36
Niladri_Biswas30-Oct-09 3:36 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
chakran30-Oct-09 4:06
chakran30-Oct-09 4:06 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
Niladri_Biswas30-Oct-09 5:11
Niladri_Biswas30-Oct-09 5:11 
GeneralRe: how to get week number and startday of the week in sql server 2008 Pin
chakran1-Nov-09 21:05
chakran1-Nov-09 21:05 
AnswerRe: how to get week number and startday of the week in sql server 2008 [modified] Pin
Niladri_Biswas29-Oct-09 22:30
Niladri_Biswas29-Oct-09 22:30 
Try this .

declare @tbl table(bugdate date)
insert into @tbl
select '12/13/2008' union all
select '12/14/2008' union all
select '12/21/2008' union all
select '12/23/2008' union all
select '12/30/2008' union all
select '1/2/2009' union all
select '1/6/2009' union all
select '12/20/2009' union all
select '12/28/2009' union all
select '1/1/2010'

select	bugdate,
		case when Datepart(yy,bugdate) = 2009 then Datepart(wk,bugdate) + 53*1
		     when Datepart(yy,bugdate) = 2010 then Datepart(wk,bugdate) + 53*2
		else Datepart(wk,bugdate)
		end as weeknumber		
		,DATEPART(dw,bugdate) weekdays
		,DATENAME(dw, DATEPART(dw,bugdate)) weekdayname
		,DATEadd(day, (1- DATEPART(dw,bugdate)), bugdate) AS startweek
		,DATENAME(dw, DATEadd(day, (1- DATEPART(dw,bugdate)), bugdate)) startweekdayname
		  from @tbl


Output:

bugdate	weeknumber	weekdays	weekdayname	startweek	startweekdayname
2008-12-13	50	7	Monday	2008-12-07	Sunday
2008-12-14	51	1	Tuesday	2008-12-14	Sunday
2008-12-21	52	1	Tuesday	2008-12-21	Sunday
2008-12-23	52	3	Thursday	2008-12-21	Sunday
2008-12-30	53	3	Thursday	2008-12-28	Sunday
2009-01-02	54	6	Sunday	2008-12-28	Sunday
2009-01-06	55	3	Thursday	2009-01-04	Sunday
2009-12-20	105	1	Tuesday	2009-12-20	Sunday
2009-12-28	106	2	Wednesday	2009-12-27	Sunday
2010-01-01	107	6	Sunday	2009-12-27	Sunday


Depending on ur requirement, accept the columns.

Note that I have multiplied 53 * 1 for 2009 & 53*2 for 2010. Now why 53?<br />
Because if you want to find out the last week of the last day of a year it will be 53. Try this Select Datepart(wk,'12/31/2008') or Select Datepart(wk,'12/31/2009') etc. The output will be 53. I am considering 2008(here) as my starting point and henceforth nothing to add with the weeks for this year. Since year 2009 is 1 ahead so I am multiplying 53 with 1(which is though of no use) and adding that to every week of that year(2009). The same rule apply for 2010 with the difference that 53 will be multiplied with 2. If we follow this rule then we can generalized a formula 53 * n where n=0,1....<br />

Note- Follow what Mr.Mycroft said. It is better for ur learning.
Smile | :)

Niladri Biswas

modified on Friday, October 30, 2009 5:03 AM

Questiondatabase Pin
sydneylandscaper28-Oct-09 21:56
sydneylandscaper28-Oct-09 21:56 
AnswerRe: database Pin
WoutL28-Oct-09 22:48
WoutL28-Oct-09 22:48 
AnswerRe: database Pin
dan!sh 29-Oct-09 0:23
professional dan!sh 29-Oct-09 0:23 

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.