SQL Server Last Day of Month: EOMONTH, Previous and Next Month

SQL Server last day of month with EOMONTH, previous and next month offsets

Use EOMONTH. The SQL Server last day of month is one call, and a second argument shifts months: It returns a date, never a time. Tested on SQL Server 2025 Developer (17.0.1000.7). EOMONTH needs SQL Server 2012 or later. EOMONTH Syntax: EOMONTH(start_date [, month_to_add]) start_date is any date type or date string; month_to_add is an … Read more >>

CURRENT_TIMESTAMP in SQL Server: Defaults, Filters and UTC

CURRENT_TIMESTAMP in SQL Server used as a DEFAULT value and stored as getdate()

CURRENT_TIMESTAMP in SQL Server returns the server’s current local date and time as a datetime. It’s the ANSI name for GETDATE(), and you write it without parentheses: My runs: SQL Server 2025 Developer (17.0.1000.7) through sqlcmd in VS Code. A raw local clock value means little on your machine, so I show types, ages and … Read more >>

Types of Backup in SQL Server: Full, Differential, Log and More

Types of backup in SQL Server shown in msdb backupset as D, I and L rows

The main types of backup in SQL Server are full, differential and transaction log backups. Copy-only, file and filegroup, partial and tail-log backups cover special jobs. Your recovery model decides which of them you’re allowed to take. Backups rescue you from a dead disk, corruption or a bad DELETE, so I ran each type, restored … Read more >>

Stored Procedure vs Function in SQL Server: Differences I Tested

Stored procedure vs function in SQL Server: timing of scalar UDF, inline TVF and stored procedure

Use a function when you need a value or rows inside SELECT, WHERE or JOIN. Use a stored procedure when the code changes data, needs a transaction or TRY…CATCH, or returns OUTPUT parameters. That’s my rule of thumb for stored procedure vs function in SQL Server, and speed doesn’t change it. On 100,000 orders an … Read more >>

SUBSTRING in SQL Server: Syntax, CHARINDEX and Examples

SQL Server SUBSTRING with CHARINDEX splitting email addresses, tested on SQL Server 2025

You’ve got a column of full names or emails, and you need one piece of each value. SUBSTRING in SQL Server does that: SUBSTRING(expression, start, length) returns length characters beginning at start, counting the first character as 1. Quick answer: SELECT SUBSTRING(‘Hannah Brooks’, 1, 6); returns Hannah. Pair it with CHARINDEX when the cut point … Read more >>

RIGHT JOIN in SQL Server: Syntax, Multiple Tables, Examples

Right join in SQL Server across three tables in VS Code: 7 employee rows, then 4 after an INNER JOIN

You have a Departments table and an Employees table. You want every department in the report, even the one nobody works in yet. Quick answer: a right join in SQL Server returns every row from the table after RIGHT JOIN plus the matching rows from the table before it. Where nothing matches, the left table’s … Read more >>