Skip to content

Commit 1b169b8

Browse files
Merge pull request #36200 from rwestMSFT/rw-0108-fix-543886
Add back older SUBSTRING syntax (UUF 543886)
2 parents ddf3d1a + 8196f46 commit 1b169b8

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

docs/t-sql/functions/substring-transact-sql.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: The SUBSTRING function returns a portion of a specified character,
44
author: MikeRayMSFT
55
ms.author: mikeray
66
ms.reviewer: randolphwest
7-
ms.date: 11/18/2025
7+
ms.date: 01/08/2026
88
ms.service: sql
99
ms.subservice: t-sql
1010
ms.topic: reference
@@ -36,12 +36,28 @@ Returns part of a character, binary, text, or image expression in [!INCLUDE [ssN
3636

3737
## Syntax
3838

39-
Syntax for [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)].
39+
::: moniker range="<=sql-server-ver16 || <=sql-server-linux-ver16"
40+
41+
Syntax for [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and earlier versions.
42+
43+
```syntaxsql
44+
SUBSTRING ( expression , start , length )
45+
```
46+
47+
::: moniker-end
48+
::: moniker range=">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-ver17 || >=sql-server-linux-ver17 || =azuresqldb-mi-current || =fabric || =fabric-sqldb"
49+
50+
Syntax for [!INCLUDE [sssql25-md](../../includes/sssql25-md.md)] and later versions, [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], [!INCLUDE [ssazuremi-md](../../includes/ssazuremi-md.md)], [!INCLUDE [ssazuresynapse-md](../../includes/ssazuresynapse-md.md)], [!INCLUDE [ssazurepdw_md](../../includes/ssazurepdw_md.md)], and [!INCLUDE [fabric-dw-short](../../includes/fabric-dw-short.md)] and [!INCLUDE [fabric-se-short](../../includes/fabric-se-short.md)] in [!INCLUDE [fabric](../../includes/fabric.md)].
4051

4152
```syntaxsql
4253
SUBSTRING ( expression , start [ , length ] )
4354
```
4455

56+
> [!NOTE]
57+
> In [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and earlier versions, [*length* is required](?view=sql-server-ver16&preserve-view=true#syntax).
58+
59+
::: moniker-end
60+
4561
## Arguments
4662

4763
#### *expression*
@@ -60,7 +76,7 @@ You can use substring with an optional *length* argument. However, if you use `N
6076

6177
## Return types
6278

63-
Returns character data if *expression* is one of the supported character data types. Returns binary data if *expression* is one of the supported **binary** data types. The returned string is the same type as the specified expression with the exceptions shown in the table.
79+
Returns character data if *expression* is one of the supported character data types. Returns binary data if *expression* is one of the supported **binary** data types. The returned string is the same type as the specified expression with the exceptions shown in the following table.
6480

6581
| Specified expression | Return type |
6682
| --- | --- |
@@ -70,7 +86,7 @@ Returns character data if *expression* is one of the supported character data ty
7086

7187
## Remarks
7288

73-
The values for *start* and *length* must be specified in number of characters for **ntext**, **char**, or **varchar** data types and bytes for **text**, **image**, **binary**, or **varbinary** data types.
89+
You must specify the values for *start* and *length* in number of characters for **ntext**, **char**, or **varchar** data types. For **text**, **image**, **binary**, or **varbinary** data types, you must specify these values in bytes.
7490

7591
The *expression* must be **varchar(max)** or **varbinary(max)** when the *start* or *length* contains a value larger than 2,147,483,647.
7692

@@ -120,7 +136,7 @@ bcd
120136
> [!NOTE]
121137
> To run the following examples, you must install the [**pubs** database](https://github.com/microsoft/sql-server-samples/tree/master/samples/databases/northwind-pubs).
122138
123-
The following example shows how to return the first 10 characters from each of a **text** and **image** data column in the `pub_info` table of the `pubs` database. **text** data is returned as **varchar**, and **image** data is returned as **varbinary**.
139+
The following example shows how to return the first 10 characters from each of a **text** and **image** data column in the `pub_info` table of the `pubs` database. The query returns **text** data as **varchar**, and **image** data as **varbinary**.
124140

125141
```sql
126142
USE pubs;
@@ -246,9 +262,9 @@ NULL
246262

247263
### E. Use SUBSTRING with optional length argument
248264

249-
**Applies to:** [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], [!INCLUDE [ssazuremi-md](../../includes/ssazuremi-md.md)], [!INCLUDE [ssazuresynapse-md](../../includes/ssazuresynapse-md.md)], [!INCLUDE [ssazurepdw_md](../../includes/ssazurepdw_md.md)], and [!INCLUDE [fabric-se-short](../../includes/fabric-se-short.md)] and [!INCLUDE [fabric-dw](../../includes/fabric-dw.md)]
265+
**Applies to:** [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], [!INCLUDE [ssazuremi-md](../../includes/ssazuremi-md.md)], [!INCLUDE [ssazuresynapse-md](../../includes/ssazuresynapse-md.md)], [!INCLUDE [ssazurepdw_md](../../includes/ssazurepdw_md.md)], [!INCLUDE [fabric-se-short](../../includes/fabric-se-short.md)], and [!INCLUDE [fabric-dw](../../includes/fabric-dw.md)]
250266

251-
The following example shows how to return only a part of a character string from a given start position. Since the *length* argument isn't provided, the length defaults to return the remaining characters in the string.
267+
The following example shows how to return only a part of a character string from a given start position. Since the *length* argument isn't provided, the function returns the remaining characters in the string.
252268

253269
```sql
254270
SELECT SUBSTRING('123abc', 4) AS y;
@@ -265,7 +281,7 @@ abc
265281
### F. Use SUBSTRING without a length argument to find replacement parts in AdventureWorks2022 inventory
266282

267283
```sql
268-
USE AdventureWorks2022;
284+
USE AdventureWorks2025;
269285
GO
270286

271287
SELECT [ProductDescriptionID],

0 commit comments

Comments
 (0)