How to Select the Latest Record in SQL Server (Per Group Too)

Select latest record in SQL Server per customer with ROW_NUMBER and a tie-breaker

Sales wants two numbers on the Monday dashboard: the newest order in the system, and each customer’s most recent order. One tie in the data decides which query you can trust. To select the latest record in SQL Server, sort by the date column descending and keep one row: SELECT TOP (1) * FROM dbo.Orders … Read more >>

How to Create Functions in SQL Server

SQL Server create functions

Two days ago, while working on the SQL query, my manager asked me to get the output in table-valued format. I created a function for the table and showed the output. A function in SQL Server is nothing but giving the required output based on the user’s input. Whatever the inputs, the function or operation … Read more >>

SQL Server Stored Procedure vs Function

Stored Procedure Vs Function

Understanding the difference between stored procedure and function is important for developers and admins when working with SQL Server. Both are important for creating reusable SQL code, but they have different purposes and characteristics. The stored procedure doesn’t have parameters and no need to return any results, whereas the function will return values. We will … Read more >>

Delete Duplicate Rows in SQL Server

using row_number to delete duplicate rows

If you have encountered duplicate values in your table, here is a tutorial on how to delete duplicate rows in SQL Server. Duplicate values lead to insufficient database storage. I’ll explain the three methods to delete duplicate rows from a table in this SQL Server tutorial. Method 1: Find Duplicate Rows in the Table using … Read more >>

Saving changes is not permitted in SQL Server

saving changes is not permitted

While working on the table from SQL Server Management Studio, I received the warning message that saving changes is not permitted. Since I have proper permissions to do DDL operations but still faced this error. After multiple troubleshooting techniques, I resolved this error. Here, I am sharing my real-time experience of solving this error. Let’s … Read more >>

SQL Server Replace Function

Replace in SQL Server

I recently worked on SQL Query, where I needed to change employee roles and salaries in the EmployeeInfo table. Here, in SQL, we can easily use the Replace Function to make the changes. SQL Server Replace Function The replace () function in SQL is a built-in function that allows us to replace all the substrings within a … Read more >>

How to Use CURRENT_TIMESTAMP Function in SQL Server?

Current Time_stamp from SQL Server

As a database developer, I was working on the query and wanted to get the exact time of a system on which the SQL server is currently running; then, I could use the CURRENT_TIMESTAMP Function provided by the SQL Server. The CURRENT_TIMESTAMP() function returns the computer’s current time stamp in ‘YYYY-MM-DD hh:mm: ss.mmm’ format. This … Read more >>

How To Convert Int to Fixed Length String in SQL Server

Sql server left join with count and where clause

While creating a function in the SQL query, I was required to convert integers into fixed-length strings in SQL Server. After multiple research studies, I found a simple and standard way of converting. In this SQL Server tutorial, you will learn how to convert int to fixed length string in SQL Server. You will understand … Read more >>

SubString in SQL Server

SQL Server Substring Example

Have you ever needed a specific portion of a string in SQL Server? Is that possible? Yes, we can retrieve a few characters from the column of a string by substring. This helpful feature allows you to change strings, easily adding flexibility to database queries. This tutorial will explain substring in SQL Server, including syntax, … Read more >>