title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | |
---|---|---|---|---|---|---|---|---|---|---|
Example: Retrieving Binary Data |
View an example of a SQL query that retrieves binary data using the RAW and BINARY BASE64 options with the FOR XML clause. |
MikeRayMSFT |
mikeray |
randolphwest |
05/05/2022 |
sql |
xml |
conceptual |
|
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]
The following query returns the product photo stored in a varbinary(max) type column. The BINARY BASE64
option is specified in the query to return the binary data in base64-encoded format.
USE AdventureWorks2022;
GO
SELECT ProductPhotoID, ThumbNailPhoto
FROM Production.ProductPhoto
WHERE ProductPhotoID = 1
FOR XML RAW, BINARY BASE64;
GO
Expect the following result:
<row ProductModelID="1" ThumbNailPhoto="base64 encoded binary data"/>