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
 How To find The current year and week

Author  Topic 

roxcy
Yak Posting Veteran

58 Posts

Posted - 2007-07-20 : 10:45:27
Hi,
I have a Serial No which has a length as 14.For eg IL010730123456. IL01 is The Default Code. 07 is the current year and 30 is the week of the year. 123456 is Serial. How shoud I find The Year and week with the help of this serial no ie The First day of the 30th week of 2007.Is it Possible?

Plz Help me with an appropriate solution.
Thanks.....

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-20 : 10:49:09
you can use substring() to do it


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

roxcy
Yak Posting Veteran

58 Posts

Posted - 2007-07-21 : 00:34:04
Could you plz help me with an Example?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-21 : 01:17:49
to get 07 use substring(Serial_no, 5, 2)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

roxcy
Yak Posting Veteran

58 Posts

Posted - 2007-07-21 : 01:50:31
Hi Khtan,
Thanks For the Reply, But that does not solve my problem.Following is the Code which gives me The year as well as Week.

Declare @str varchar(14)
Declare @yr int
Declare @wk int
Set @str ='IL010730123456'
Select @yr=substring(@str,5,2),@wk=substring(@str,7,2)
Select @yr as year
Select @wk as week

This code gives me the output as Year 7 and week as 30. What my requirement is I want to display the 1st day of the 30th week of the current year 2007 ie 2007-07-15

I hope you got my problem....
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-21 : 01:56:10
[code]Declare @str varchar(14)
Declare @yr varchar(2)
Declare @wk varchar(2)
Set @str ='IL010730123456'
Select @yr=substring(@str,5,2),@wk=substring(@str,7,2)
Select @yr as year
Select @wk as week[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -