Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9073939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:31:42+00:00 2026-06-16T18:31:42+00:00

Anyone knows how to built temp table of week using T-SQL query? I heard

  • 0

Anyone knows how to built temp table of week using T-SQL query?

I heard there has a lot of type of calculations for that, Gregorian or etc… My needs are ISO Week No and bind to temp table depends on week no.

The temp table has 2 columns : ISOWeekNo and WeekName

ISOWeekNo   WeekName
1           01 Jan 2013 To 07 Jan 2013
2           08 Jan 2013 To 14 Jan 2013

How do I build programmatically in T-SQL Query based on ISO Week No?

Updated : I want to pass the parameter year only. e.g : 2013

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:31:43+00:00Added an answer on June 16, 2026 at 6:31 pm

    EDIT: Added WHERE clause to terminate for sought year only.

    This seems to match the Wikipedia description and I am sure there is room for optimisation.
    Mikael, I copied your formatting code for the friendly column, thank you.
    This code will work on SQL Server 2008 onwards because of the use of the ISOWEEK datepart.

    use tempdb
    go
    
    DECLARE  @Year          SMALLINT = 2013
            ,@FirstISOWKDay DATETIME
    
    ;WITH FindISOWEEKFirstDay AS
    (
        SELECT DT   = DATEADD(DAY, -7, DATEFROMPARTS(@Year, 1, 1))
        UNION ALL
        SELECT DATEADD(DAY, 1, DT)
        FROM FindISOWEEKFirstDay
        WHERE DATEADD(DAY, 1, DT) < DATEADD(DAY, 14, DATEFROMPARTS(@Year, 1, 1))
    )
    SELECT TOP 1 @FirstISOWKDay = DT
    FROM FindISOWEEKFirstDay
    WHERE DATEPART(ISO_WEEK, DT) = 1
    ORDER BY DT ASC -- Eliminate probability of arb sorting (Thanks Mikael)
    ;WITH Base10 (n) AS
    (
        SELECT 1    UNION ALL   SELECT 1    UNION ALL   SELECT 1    UNION ALL
        SELECT 1    UNION ALL   SELECT 1    UNION ALL   SELECT 1    UNION ALL
        SELECT 1    UNION ALL   SELECT 1    UNION ALL   SELECT 1    UNION ALL
        SELECT 1    
    )
    ,Base1000 (n) AS
    (
        SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL))-1
        FROM Base10 T1, Base10 T2, Base10 T3
    )
    SELECT   Start      = DATEADD(DAY, n*7, @FirstISOWKDay)
            ,[End]      = DATEADD(DAY, n*7 + 6, @FirstISOWKDay)
            ,Friendly   = CONVERT(VARCHAR(101), DATEADD(DAY, n*7, @FirstISOWKDay), 106)+' To '+CONVERT(VARCHAR(101), DATEADD(DAY, n*7 + 6, @FirstISOWKDay), 106)
            ,ISOWEEK    = DATEPART(ISO_WEEK, DATEADD(DAY, n*7, @FirstISOWKDay))
    FROM Base1000
    -- Filter to terminate, resulting only in sought year's calendar
    WHERE DATEPART(YEAR, DATEADD(DAY, n*7 + 6, @FirstISOWKDay)) = @Year
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone know if there is anything built into rails to the effect of validates_signularity_of
Does anyone know of any publicly available Question answering applications which have built using
Before I start writing one I was wondering if anyone knows of a built-in
just wondering if anyone knows of any pre built content switchers powered by jquery
Curious if anyone knows if codeigniter's form validation built in max_length[n] and min_length[n] functions
Anyone knows how to create one? I know this question has been asked before
So I am making an application using cakePHP. I am wondering if anyone knows
Anyone knows where I could find a complete list of built-in DOM events in
I was wondering if anyone knows of a quick way or if anyone has
Is there an easy built-in-way of combining paths for using them as a single

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.