QuestionQ23

Design and develop database solutions

You have a SQL database in Microsoft Fabric containing an nvarchar(max) column named MessageText. An ID is always present within the first paragraph of MessageText.

You need to write a Transact-SQL query using REGEXP_SUBSTR to extract the ID from MessageText.

What should you include in the query?

Explanation

In SQL Server 2025 / SQL database in Microsoft Fabric, the regular-expression functions have an important restriction: LOB types (varchar(max) and nvarchar(max), up to 2 MB) are supported only by REGEXP_LIKE, REGEXP_COUNT, and REGEXP_INSTR. REGEXP_SUBSTR, REGEXP_REPLACE, REGEXP_MATCHES, and REGEXP_SPLIT_TO_TABLE do NOT accept LOB input. Because MessageText is nvarchar(max), you must first cast it to a non-LOB type such as nvarchar(4000) before calling REGEXP_SUBSTR, which is fine here since the ID always appears in the first paragraph (choice B). A case-sensitive COLLATE clause (C) changes matching behavior but does not remove the LOB restriction, TRY_CONVERT to varchar(max) (D) is still a LOB, and STRING_ESCAPE (A) is unrelated.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!