---
title: "What is Difference between CAST vs CONVERT in SQL Server?"  
description: "What is Difference between CAST vs CONVERT in SQL Server?"  
author: "Ravi Vishwakarma"  
published: 2026-05-10  
updated: 2026-05-12  
canonical: https://answers.mindstick.com/qa/116581/what-is-difference-between-cast-vs-convert-in-sql-server  
category: "database"  
tags: ["database", "sql server"]  
reading_time: 3 minutes  

---

# What is Difference between CAST vs CONVERT in SQL Server?

**What is [Difference](https://www.mindstick.com/blog/398/difference-between-object-type-and-var-type) between [CAST](https://answers.mindstick.com/qa/97273/how-to-cast-a-baitcaster) vs [CONVERT](https://www.mindstick.com/blog/698/convert-text-document-to-pdf-file) in [SQL Server](https://www.mindstick.com/articles/12343/sql-server-2017-ctp-2-0-now-available)?**

## Answers

### Answer by Anubhav Sharma

In Microsoft [SQL](https://www.mindstick.com/articles/202/the-detailed-concept-of-stored-procedure-in-sql-server) [Server](https://www.mindstick.com/articles/710/apache-server-installation-on-windows), both `CAST` and `CONVERT` are used to change a value from one data type to another, but they differ in syntax, flexibility, and portability.

## 1. Basic Syntax

## CAST

```plaintext
CAST(expression AS data_type)
```

Example:

```plaintext
SELECT CAST(123.456 AS INT);
```

Result:

```plaintext
123
```

## CONVERT

```plaintext
CONVERT(data_type, expression [, style])
```

Example:

```plaintext
SELECT CONVERT(INT, 123.456);
```

Result:

```plaintext
123
```

## 2. Main Differences

| Feature | CAST | CONVERT |
| --- | --- | --- |
| ANSI SQL Standard | Yes | No (SQL Server-specific) |
| Portability | Better | Less portable |
| Formatting options | Limited | Supports style formatting |
| Readability | More standard | More flexible for dates |
| Extra style parameter | No | Yes |

## 3. Date Formatting (Biggest Practical Difference)

`CONVERT` supports a **style code**, especially useful for formatting dates.

Example:

```plaintext
SELECT CONVERT(VARCHAR, GETDATE(), 103);
```

Result:

```plaintext
12/05/2026
```

Here:

`103` = British/French date format (`dd/mm/yyyy`)

Equivalent with `CAST`:

```plaintext
SELECT CAST(GETDATE() AS VARCHAR);
```

This gives a default format only — no custom style control.

## 4. Common Style Codes in CONVERT

| Style | Format |
| --- | --- |
| 101 | mm/dd/yyyy |
| 102 | yyyy.mm.dd |
| 103 | dd/mm/yyyy |
| 104 | dd.mm.yyyy |
| 120 | yyyy-mm-dd hh:mi:ss |
| 121 | ODBC with milliseconds |

Example:

```plaintext
SELECT CONVERT(VARCHAR, GETDATE(), 120);
```

## 5. Performance Difference

In most real-world cases:

- Performance difference is negligible.
- SQL Server optimizes both similarly.

Choose based on:

- readability
- portability
- formatting needs

## 6. When to Use Which?

## Use CAST when:

- Writing portable SQL
- Following ANSI standards
- Simple type conversion is enough

Example:

```plaintext
SELECT CAST(price AS DECIMAL(10,2))
FROM Products;
```

## Use CONVERT when:

- Working specifically in SQL Server
- You need formatted date/time output
- You need style codes

Example:

```plaintext
SELECT CONVERT(VARCHAR(10), OrderDate, 103)
FROM Orders;
```

## 7. TRY_CAST and TRY_CONVERT

SQL Server also provides safer versions:

```plaintext
TRY_CAST('abc' AS INT)
```

Returns:

```plaintext
NULL
```

instead of throwing an error.

Similarly:

```plaintext
TRY_CONVERT(INT, 'abc')
```

Very useful for data cleaning and ETL work.

## Quick Summary

| Use Case | Recommended |
| --- | --- |
| Standard SQL | CAST |
| Date formatting | CONVERT |
| Cross-database compatibility | CAST |
| SQL Server-specific formatting | CONVERT |
| Safe conversion | TRY_CAST / TRY_CONVERT |

A common rule developers follow:

> Use `CAST` by default, and use `CONVERT` when you need formatting styles.


---

Original Source: https://answers.mindstick.com/qa/116581/what-is-difference-between-cast-vs-convert-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
