?
Solved

Find Monday in iso_week 1

Posted on 2015-02-20
2
Medium Priority
?
75 Views
Last Modified: 2015-02-20
Hi!

I need a sql query to provide me the Monday in iso_week 1 for any given year.

in 2015 it should return '2014-12-29'
in 2016 it should return '2016-01-04'
in 2017 it should return '2017-01-02'

Thanks,
0
Comment
Question by:intimenordic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40620857
Either:

select dateadd(day,2-datepart(dw,'20130101')+iif(datepart(dw,'20130101')>5,7,0),'20130101') as ISOWeek1

Open in new window


or, if you want to define it once:

declare @year as char(4)
set @year = '2027'

select dateadd(day,2-datepart(dw,@year + '0101')+iif(datepart(dw,@year + '0101')>5,7,0),@year + '0101') as ISOWeek1

Open in new window

0
 

Author Closing Comment

by:intimenordic
ID: 40620863
Perfect! Just used getdate for declaring, since this is a runtime thing.

declare @year as char(4)
set @year = year(getdate())
select dateadd(day,2-datepart(dw,@year + '0101')+iif(datepart(dw,@year + '0101')>5,7,0),@year + '0101') as ISOWeek1

Thanks, and have a great weekend!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question