- Error number
- 8169
- Severity
- 16 (user-correctable error)
- State
- 2
- Product
- Microsoft SQL Server Database Engine
- Versions
- All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
- Category
- Data Type & Conversion
- Last reviewed
- 24 October 2026
On this page
What it means
Error 8169 means a piece of text had to become a uniqueidentifier (GUID) and is not in a GUID format SQL Server accepts, for example a placeholder, an empty string or 32 hex digits without hyphens.
A uniqueidentifier is written as 32 hexadecimal digits in groups of 8, 4, 4, 4 and 12, separated by hyphens, optionally inside braces: 6F9619FF-8B86-D011-B42D-00C04FC964FF. When text meets a uniqueidentifier, in a CAST, an INSERT into a GUID column, a comparison in WHERE or a parameter, SQL Server parses it. If it does not fit that pattern, the statement fails at run time with 8169 at severity 16. Like other conversion errors it does not quote the offending value, so you have to find the row.
The parser is strict about the start of the string and lenient about the end. A leading space, a missing hyphen or a letter outside A to F fails; braces are accepted; and in our tests characters after a valid 36-character GUID were ignored rather than rejected. So a clean result does not prove the input was clean. Because data type precedence converts the text side, a comparison such as WHERE device_id = @search fails on the first bad search string even if no row would match.
Common causes
- Placeholder values such as
N/A,noneor the stringNULLin a varchar column loaded into a uniqueidentifier column. - GUIDs written without hyphens (the 32-digit format many APIs and .NET
ToString("N")produce). - An empty string from a web form or API sent as a GUID parameter or compared with a GUID column.
- Leading spaces, quotes or other wrapping characters left over from a CSV import.
- A search box that compares whatever the user typed with a uniqueidentifier column.
Diagnose it
Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.
Find the rows that would fail
SELECT device_ref
FROM dbo.Staging
WHERE device_ref IS NOT NULL
AND TRY_CONVERT(uniqueidentifier, device_ref) IS NULL; Every value that raises 8169. TRY_CONVERT returns NULL instead of an error, so this query always completes.
Group the bad values by length and shape
The length tells you what kind of problem you have: 32 is a GUID without hyphens, 38 is one in braces or quotes, 0 is an empty string.
SELECT LEN(device_ref) AS text_length,
DATALENGTH(device_ref) AS bytes,
COUNT(*) AS row_count,
MIN(device_ref) AS sample
FROM dbo.Staging
WHERE TRY_CONVERT(uniqueidentifier, device_ref) IS NULL
GROUP BY LEN(device_ref), DATALENGTH(device_ref)
ORDER BY row_count DESC; A few groups you can fix with one rule each. A difference between bytes and text length points at trailing spaces.
How to fix it
Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.
Load with TRY_CONVERT and keep the rejects
Changes dataConvert valid values and turn the rest into NULL. Only do this when NULL is acceptable for that column; otherwise write the rejects to a separate table and review them.
INSERT INTO dbo.Readings (device_id)
SELECT TRY_CONVERT(uniqueidentifier, device_ref)
FROM dbo.Staging
WHERE TRY_CONVERT(uniqueidentifier, device_ref) IS NOT NULL;
Put the hyphens back into 32-digit GUIDs
Read-onlyThe 32-digit form only lacks the separators. STUFF inserts them at positions 9, 14, 19 and 24.
DECLARE @raw varchar(32) = '6F9619FF8B86D011B42D00C04FC964FF';
SELECT CONVERT(uniqueidentifier,
STUFF(STUFF(STUFF(STUFF(@raw, 9, 0, '-'), 14, 0, '-'), 19, 0, '-'), 24, 0, '-')) AS device_id;
Treat empty input as NULL and pass a typed parameter
Client or network sideIn application code, parse the GUID before calling the database and send it as a uniqueidentifier parameter. Inside T-SQL, NULLIF turns an empty string into NULL, which converts without an error.
DECLARE @search varchar(50) = '';
SELECT name
FROM dbo.Devices
WHERE device_id = TRY_CONVERT(uniqueidentifier, NULLIF(@search, ''));
Examples
Loading a staging column that contains N/A
SET NOCOUNT ON;
CREATE TABLE dbo.Staging (device_ref VARCHAR(50));
INSERT INTO dbo.Staging VALUES ('6F9619FF-8B86-D011-B42D-00C04FC964FF'), ('N/A');
CREATE TABLE dbo.Readings (device_id UNIQUEIDENTIFIER);
INSERT INTO dbo.Readings (device_id)
SELECT device_ref FROM dbo.Staging; -- 'N/A' is not a GUID
Msg 8169, Level 16, State 2, Line 6 Conversion failed when converting from a character string to uniqueidentifier.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
A GUID without hyphens
SELECT CAST('6F9619FF8B86D011B42D00C04FC964FF' AS uniqueidentifier) AS device_id;
Msg 8169, Level 16, State 2, Line 1 Conversion failed when converting from a character string to uniqueidentifier.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
An empty search value compared with a GUID column
SET NOCOUNT ON;
CREATE TABLE dbo.Devices (device_id UNIQUEIDENTIFIER PRIMARY KEY, name NVARCHAR(50));
INSERT INTO dbo.Devices VALUES ('6F9619FF-8B86-D011-B42D-00C04FC964FF', N'Till 1');
DECLARE @search varchar(50) = ''; -- nothing typed in the search box
SELECT name FROM dbo.Devices WHERE device_id = @search;
Msg 8169, Level 16, State 2, Line 6 Conversion failed when converting from a character string to uniqueidentifier.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
How to prevent it
Keep GUIDs typed as uniqueidentifier from the application to the table: parameters, staging columns and variables. Validate text input at the boundary with TRY_CONVERT, and decide explicitly what happens to values that fail instead of letting the first bad row stop a load.
Agree on one textual format (36 characters with hyphens) with every system that sends you identifiers. For when to use GUID keys at all, see SQL data types explained.
Common questions
Does SQL Server accept GUIDs with braces?
Yes. Both 6F9619FF-8B86-D011-B42D-00C04FC964FF and the same value inside curly braces convert. The 32-digit form without hyphens does not.
Why did a GUID with extra text at the end not fail?
In our tests on SQL Server 2025, characters after a valid 36-character GUID were ignored. Check the length of incoming values if extra text could mean a data problem.
How do I find which value caused error 8169?
Select the source column where TRY_CONVERT(uniqueidentifier, column) is NULL but the column itself is not. Those rows are the ones the conversion rejects.
Learn more on CodeWithSQL
Official documentation
- uniqueidentifier (Transact-SQL)
- TRY_CONVERT (Transact-SQL)
- Database Engine events and errors 8000 to 8999
Last technically reviewed 24 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.