If you’ve used T-SQL you will probably be familiar with the GO
command. This command is often placed at the end of a batch of statements.
Category: SQL Server
Extract the Week Number from a Date in SQL Server (T-SQL)
You can use the T-SQL function DATEPART()
to return the week number from a date in SQL Server.
By “week number” I mean the week’s number within the year of the specified date.
Continue readingReturn the ISO Week Number from a Date in SQL Server (T-SQL)
If you need to extract the ISO week number from a date in SQL Server, you can use the iso_week
argument when calling the DATEPART()
function. You can alternatively use the isowk
or isoww
arguments to do the same thing.
By “ISO week”, I’m referring to the ISO 8601 date and time standard.
Continue readingGet the Right Part of a String in SQL Server (T-SQL)
In SQL Server, you can use the RIGHT()
function to extract the right part of a string.
It works exactly the same as the LEFT()
function (which returns the left part of a string), except that it returns the right part of the string.
Get the Left Part of a String in SQL Server (T-SQL)
In SQL Server, you can use the LEFT()
function to extract the left part of a string.
It works exactly the same as the RIGHT()
function (which returns the right part of a string), except that it returns the left part of the string.
Create a Database in SQL Server (T-SQL)
Many developers and database administrators create databases using GUI tools such as SQL Server Management Studio (SSMS), Azure Data Studio, etc.
But it can be much quicker to create databases using SQL. This is especially true if you have various environments that you need to recreate the same database on. You can run the same script against each environment, and the database will be created within seconds each time.
In SQL Server, we do this with T-SQL. T-SQL stands for Transact-SQL, and it is SQL Server’s extension to SQL.
Below is an example of using T-SQL to create a database in SQL Server.
Continue readingCreate a Table in SQL Server (T-SQL)
Creating a SQL Server database table using T-SQL can involve a small amount of code or a large amount, depending on your requirements for the table.
In this article, I create a basic a table with T-SQL that requires a minimum amount of code.
Continue reading2 Ways to Return the Server Name in SQL Server (T-SQL)
Here are a couple of T-SQL methods you can use to return the server name in SQL Server.
Continue readingReturn the Current Login Name in SQL Server (T-SQL)
You can use the SUSER_NAME()
function to see the login name that you’re currently using to access SQL Server.
This function returns returns the login identification name of the user. It also allows you to get the login name of any other user, based on their login identification number.
Continue readingChange the Language for the Current Session in SQL Server
You may know that when you connect to SQL Server, the language for that session is usually determined by your login. When a login is created, it is assigned a default language.
The session language determines the datetime formats and system messages.
While you can certainly change the default language for a login, you can also override the default language within a session if you need to. You can toggle back and forth between languages if required. Or you could even open two separate connections and apply a different language to each of them.
This article explains how to change the language within a session.
Continue reading