# MySQL vs. SQL Server: the same jobs, different functions

Trim a name, round up to whole cartons, count the days an order was late. MySQL and SQL Server both do these jobs, but often with different words, and a few look alike while doing different things.

By Gregor Dzierzon · Published November 20, 2026

![>](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/84985565d57e4107a91e3be58deafec7.webp)

Learn SQL on one database and you'll soon meet the other. A class teaches MySQL, and your first job runs SQL Server, or the other way around. The good news: `SELECT`, `WHERE`, `JOIN` and `GROUP BY` read the same in both. The surprises are in the **built-in functions**, the small tools that clean up text, round numbers and work with dates.

Here are the everyday jobs side by side, then the five differences most likely to trip you up.

![Two workbenches side by side, labeled MySQL and SQL Server, each holding the same three tools, a magnifying glass, a calendar and a label maker, tagged with that database's name for the job: LOCATE and CHARINDEX, DATE_ADD and DATEADD, DATE_FORMAT and FORMAT](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/414fae404e974d7aaa6732c1f8775151.webp)

## The same jobs, side by side

| The job | MySQL | SQL Server (T-SQL) |
|---|---|---|
| Remove spaces at both ends | `TRIM(text)` | `TRIM(text)` |
| Swap one piece of text for another | `REPLACE(text, find, new)` | `REPLACE(text, find, new)` |
| Find where a piece of text is | `LOCATE(find, text)` | `CHARINDEX(find, text)` |
| How many characters | `CHAR_LENGTH(text)` | `LEN(text)` |
| Round up, round down | `CEILING`, `FLOOR` | `CEILING`, `FLOOR` |
| The date and time now | `NOW()` | `GETDATE()` |
| Days between two dates | `DATEDIFF(later, earlier)` | `DATEDIFF(day, earlier, later)` |
| A date 30 days later | `DATE_ADD(d, INTERVAL 30 DAY)` | `DATEADD(day, 30, d)` |
| A date as text for people | `DATE_FORMAT(d, '%M %e, %Y')` | `FORMAT(d, 'MMMM d, yyyy')` |
| A stand-in for NULL | `IFNULL(x, 'n/a')` or `COALESCE` | `ISNULL(x, 'n/a')` or `COALESCE` |

Both databases count text positions from 1, not from 0 as Java and C# do: the space in `Maria Anders` is at position 6 in both. And some functions are spelled the same everywhere, `COALESCE`, `NULLIF`, `UPPER`, `LOWER`, `ROUND` and `ABS` among them.

## Five differences that bite

**1. DATEDIFF takes its dates in opposite orders.** In MySQL the later date comes first and the answer is always in days: `DATEDIFF('2026-03-18', '2026-03-16')` is 2 ([MySQL manual](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html)). SQL Server names the unit first, then the earlier date: `DATEDIFF(day, '2026-03-16', '2026-03-18')` is 2 ([Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql)). Copy one into the other without swapping and every late order looks early.

**2. CONCAT and NULL.** Building a label from a city and a region, where the region is `NULL`:

```sql
-- MySQL: NULL, the whole label is gone
SELECT CONCAT('Berlin', ', ', NULL);

-- SQL Server: 'Berlin, ' (the NULL counts as empty text)
SELECT CONCAT('Berlin', ', ', NULL);
```

MySQL's `CONCAT` gives `NULL` if any part is `NULL` ([MySQL manual](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html)); SQL Server's treats a `NULL` as empty text ([Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/functions/concat-transact-sql)). Both have `CONCAT_WS(', ', city, region)`, which skips the `NULL`s and leaves no stray comma.

**3. ISNULL means two different things.** In SQL Server, `ISNULL(region, 'n/a')` supplies a stand-in ([Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/functions/isnull-transact-sql)). In MySQL, `ISNULL(region)` takes one value and answers a question: 1 if it's `NULL`, 0 if it isn't ([MySQL manual](https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html)). `COALESCE(region, 'n/a')` works the same in both, so it's the one to reach for.

**4. Dividing whole numbers.** The warehouse packs 12 units to a carton, and a product has 39 in stock. In MySQL, `39 / 12` is `3.2500`, so `CEILING(39 / 12)` is the 4 cartons you need ([MySQL manual](https://dev.mysql.com/doc/refman/8.4/en/arithmetic-functions.html)). In SQL Server, `39 / 12` is `3`, because dividing two whole numbers drops the remainder ([Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/divide-transact-sql)), so `CEILING(39 / 12)` is 3, one carton short. Write `39 / 12.0` and SQL Server gets 4 too.

**5. Letter case in REPLACE.** MySQL's `REPLACE` matches letter case exactly, so `REPLACE('Chai', 'c', 'k')` changes nothing ([MySQL manual](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html)). SQL Server compares text by the database's collation, and the usual one ignores case, so the same call gives `khai` ([Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/functions/replace-transact-sql)).

## A habit that travels

When a function is spelled the same in both, prefer it: `COALESCE` over `IFNULL` or `ISNULL`, `CONCAT_WS` when parts might be `NULL`. When it isn't, keep the other database's spelling in mind, and test the edge cases (a `NULL`, a 0, the last day of a month) on the database you're really using.

## Go deeper

Each database gets a full lesson, with the problem each function solves, the Northwind sample data, a practice box and questions to check yourself:

- [More MySQL Functions](https://www.ask-codey.com/lessons/more-mysql-functions?course=java-full-stack-bootcamp), in the Java Full-Stack Bootcamp
- [More T-SQL Functions](https://www.ask-codey.com/lessons/more-t-sql-functions?course=csharp-full-stack-bootcamp), in the C# Full-Stack Bootcamp

**On one page:** [the MySQL vs. SQL Server functions cheat sheet](https://www.ask-codey.com/cheat-sheets/mysql-vs-sql-server-functions-cheat-sheet), to keep or to share.

## Sources

- Oracle, [Date and Time Functions](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html), MySQL 8.4 Reference Manual: `DATEDIFF` (later date first, in days), `DATE_ADD`, `DATE_FORMAT`, `NOW`.
- Oracle, [String Functions and Operators](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html), MySQL 8.4 Reference Manual: `CONCAT` gives `NULL` if any part is `NULL`, `CONCAT_WS`, `REPLACE` matches case, `LOCATE`, `CHAR_LENGTH`.
- Oracle, [Comparison Functions and Operators](https://dev.mysql.com/doc/refman/8.4/en/comparison-operators.html), MySQL 8.4 Reference Manual: MySQL's one-value `ISNULL()` and `COALESCE`.
- Oracle, [Arithmetic Operators](https://dev.mysql.com/doc/refman/8.4/en/arithmetic-functions.html), MySQL 8.4 Reference Manual: `/` keeps the decimals.
- Microsoft, [DATEDIFF (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql), Microsoft Learn: the unit, then the start date, then the end date.
- Microsoft, [CONCAT (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/functions/concat-transact-sql), Microsoft Learn: a `NULL` counts as empty text.
- Microsoft, [ISNULL (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/functions/isnull-transact-sql), Microsoft Learn: a stand-in for `NULL`.
- Microsoft, [/ (Divide) (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/divide-transact-sql), Microsoft Learn: whole numbers divide to a whole number.
- Microsoft, [REPLACE (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/functions/replace-transact-sql), Microsoft Learn: matching follows the collation.

Tags: [mysql](https://www.ask-codey.com/blog?tag=mysql), [sql](https://www.ask-codey.com/blog?tag=sql), [sql-server](https://www.ask-codey.com/blog?tag=sql-server), [t-sql](https://www.ask-codey.com/blog?tag=t-sql)

## Glossary subjects

- [SQL](https://www.ask-codey.com/glossary/subjects/sql)

## More posts

- Previous: [Why I built Ask Codey: a reason to set sail](https://www.ask-codey.com/blog/why-i-built-ask-codey)
- Next: [5 LINQ methods you should know](https://www.ask-codey.com/blog/five-linq-methods-you-should-know)

Source: https://www.ask-codey.com/blog/mysql-vs-sql-server-functions
