create the dateid table in sql server

Vineet S 1,090 Reputation points
2024-07-10T14:38:36.3933333+00:00

Hi ,

how to populate the dateid and date in dimtime table using script as below output upto 2029 excluding saturday and sunday

create table table (dateid int,day varchar(23),

dateid | day

20240601 | 2024 June 01

20290601 | 2029 June 01

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,228 questions
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
855 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,039 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,943 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,599 questions
{count} votes

Accepted answer
  1. Naomi Nosonovsky 7,886 Reputation points
    2024-07-10T16:19:10.4733333+00:00

    Take a look at this link https://www.mssqltips.com/sqlservertip/4054/creating-a-date-dimension-or-calendar-table-in-sql-server/

    If you just want to modify your code, you can add

    BEGIN
    IF DATEPART(weekday, @dIncr) NOT IN (1,7)
    
    INSERT INTO _Dates (d) VALUES( @dIncr )
    
    SELECT @dIncr = DATEADD(DAY, 1, @dIncr )
    
    END
    
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.