SQL Query to Set First Day of the Week in a Database
Last Updated :
13 Apr, 2021
In this article, we are going to write a SQL script to Set the first day of the week in a Database. Below is the implementation for the same. You should have MSSQL in your server.
Query in SQL -
A query is a request for data or information from a database table or combination of tables. This data can be used for various purposes like Training a model, finding the patterns in the data, etc.
Let's start by creating a DataBase first -
Step 1:
CREATE DATABASE GFG
Step 2: Use this database -
USE GFG
Step 3: Create a table as the days -
CREATE TABLE geeksforgeeks
(VALUE integer,
FirstDay varchar(20))
Describe this table -
sp_help 'dbo.daysData'
Schema of table
Step 4: Insert values in the table -
USE [GFG]
GO
INSERT INTO [dbo].[geeksforgeeks]
([VALUE]
,[FirstDay])
VALUES
(1, 'Monday')
GO
INSERT INTO [dbo].[geeksforgeeks]
([VALUE]
,[FirstDay])
VALUES
(2, 'Tuesday')
GO
INSERT INTO [dbo].[geeksforgeeks]
([VALUE]
,[FirstDay])
VALUES
(3, 'Wednesday')
GO
INSERT INTO [dbo].[geeksforgeeks]
([VALUE]
,[FirstDay])
VALUES
(4, 'Thursday')
GO
INSERT INTO [dbo].[geeksforgeeks]
([VALUE]
,[FirstDay])
VALUES
(5, 'Friday')
GO
INSERT INTO [dbo].[geeksforgeeks]
([VALUE]
,[FirstDay])
VALUES
(6, 'Saturday')
GO
INSERT INTO [dbo].[geeksforgeeks]
([VALUE]
,[FirstDay])
VALUES
(7, 'Sunday')
GO
Select all the values
Step 5: Check the existing First day of the week -
SELECT @@DATEFIRST
Pre defined datefirst
Step 6: Now set the First Day of the week using DATEFIRST -
SET DATEFIRST 1
Step 7: Check the DATEFIRST value -
Date first has been changed
As we can see we have successfully set our date first as 1 i.e, monday
Similar Reads
SQL Query to Get First and Last Day of a Week in a Database An SQL query is a single line statement of a Program written in a particular language to perform a specific task. A query consists of some pre-defined functions in SQL like SELECT, CREATE, etc. So, in this article, we will learn about SQL query to get the first and last day of a week in a database.
2 min read
SQL Query to Get First and Last Day of a Month in a Database In SQL, working with date and time data is critical for tasks like reporting, scheduling, and data analysis. Determining the first and last day of a month is a common requirement. SQL provides powerful functions like DATE_SUB, DAYOFMONTH, and LAST_DAY to make these calculations straightforward.In th
4 min read
How to Exclude Weekend Days in a SQL Server Query? With this article, we will learn how to exclude weekend days in a SQL server query. For this task, we use the DATEADD ( ) MS.SQL server function. This function in SQL Server is used, to sum up, a time or a date interval to a specified date then returns the modified date. Syntax : DATEADD(interval, n
2 min read
How to Create Daily, Weekly, and Monthly Report in SQL Server? SQL Server is a versatile database and a most used database throughout the world. In this article, let us see SQL queries how to get Daily, Weekly, and Monthly reports from SQL Server. Let us start in creating a database and sample details Step 1: Database creation Command to create the database. He
3 min read
How to Find Day Name From Date in SQL Server? Finding the day name from a specific date is a common task in SQL Server, useful for generating reports, analyzing trends, or scheduling. SQL Server provides two primary methods such as the DATENAME() function and the FORMAT() function. In this article, We will learn about How to Find Day Name From
4 min read
SQL Query to find All Sundays Between Two Dates To find all the Sundays in between two days using SQL Language, we will be using the "Date Functions" defined in SQL. Apart from these we will be using CTE ( View) idea too. Basic idea: So basically we are given two days, and we are required to list all Sundays between these two days. Thinking a lit
2 min read