Here are three T-SQL functions that you can use to extract the month from a date in SQL Server.
SQL Server
Get the Underlying Columns of a View Based on its Result Set
One of the great things about database views, is that they allow you to run complex queries without needing to know the underlying database schema.
Yes, it’s true that you need to know the underlying schema when you create the view, but you only need to do that once. Once you’ve created it, you can query that view all day long without needing to remember all the table and column names, etc.
Views typically combine data from multiple tables into a single, virtual table, which makes it kind of like a “black box”. As long as it works as designed, you don’t need to concern yourself with the hidden details.
But what if you do want to check a view for its underlying tables and columns?
Override the Query Optimizer for your T-SQL Joins with FORCEPLAN
The SET FORCEPLAN statement overrides the logic used by the SQL Server query optimizer to process a T-SQL SELECT statement.
More specifically, when FORCEPLAN is set to ON, the query optimizer processes a join in the same order as the tables appear in the FROM clause of a query.
This also forces the use of a nested loop join unless other types of joins are required to construct a plan for the query, or they are requested with join hints or query hints.
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.
Return 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.
Get 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.