Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 user defined functions

Author  Topic 

gsrikanthreddi
Starting Member

14 Posts

Posted - 2007-04-15 : 07:04:46
Hi,
Iam new to sql server. I want to create a user defined function to get date in a year(starting day of a week-i.e sunday date) when we give week number as argument. can any body help on this issue?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-15 : 07:07:11
Read this http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762



KH

Go to Top of Page

gsrikanthreddi
Starting Member

14 Posts

Posted - 2007-04-15 : 09:32:42
Thnx for ur support,

But i has not solved my problem yet,
My issue is for example,
if i give week number say 15
the function should return sunday date of the 15th week in the present year.

Plz help me.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-15 : 09:47:55
See which one is applicable for you case.
F_START_OF_WEEK http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47307
F_ISO_WEEK_OF_YEAR http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=60510


KH

Go to Top of Page

gsrikanthreddi
Starting Member

14 Posts

Posted - 2007-04-15 : 10:21:07
thank u for ur reply.
But i could not get solution.In the links given,date is passes as an argument.but we want week number should be passed as an argument.example if we give 15 as week number then it should display 8-4-2007 .
so please giv suitable link
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-15 : 10:41:34
quote:
Originally posted by gsrikanthreddi

thank u for ur reply.
But i could not get solution.In the links given,date is passes as an argument.but we want week number should be passed as an argument.example if we give 15 as week number then it should display 8-4-2007 .
so please giv suitable link


What is your definition of a WEEK ?
Your WEEK is starting from which day ?
What is the starting date of your week 1 for 2007?


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-15 : 10:42:51
Unless your week definition follows ISO WEEK or SQL definition of week no, you will be much better of having your own calendar table which you define your own week no.


KH

Go to Top of Page

gsrikanthreddi
Starting Member

14 Posts

Posted - 2007-04-15 : 10:45:24
Hi again,

My week starts from sunday through saturday,
and my Week 1 starts from 04-01-2007

regards'
Srikanth
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-15 : 10:50:43
quote:
and my Week 1 starts from 04-01-2007

Please specify your date in YYYY-MM-DD. I have not idea that is Jan 4 or Apr 1.


KH

Go to Top of Page

gsrikanthreddi
Starting Member

14 Posts

Posted - 2007-04-15 : 10:53:11
Hi,

Sorry i made u confuse,
My week 1 starts from 2007-01-04. i.e it is january 4th
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-15 : 11:03:49
quote:
My week starts from sunday through saturday

Jan 4 2007 ? it is a Thursday. Not Sunday ??

select datename(weekday, '20070104')



KH

Go to Top of Page

gsrikanthreddi
Starting Member

14 Posts

Posted - 2007-04-15 : 11:08:49
Hi,

Sorry again,

my week 1 starts on 2007-01-07.
so if i give week 1 as input then i shud get 2007-01-07

thnx & regards,
Srikanth
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-15 : 11:15:39
[code]select dateadd(week, 15 - 1, '2007-01-07')[/code]


KH

Go to Top of Page

gsrikanthreddi
Starting Member

14 Posts

Posted - 2007-04-15 : 11:45:10
Hi,

I will try this code.

Thnx & regards
Srikanth.
Go to Top of Page
   

- Advertisement -