Convert VARBINARY (BLOB) to Base64 String using T-SQL

11766
2
07-12-2017 06:35 AM
TL2
by
Occasional Contributor III

I am trying to convert the attachment tables DATA tab (BLOB/VARBINARY) into Base64.  

USE UTILITIES
SELECT CAST(CAST('' as XML).value('xs:base64Binary(sql:column("DATA"))', 'VARBINARY(MAX)') AS NVARCHAR(MAX))

FROM FeatureClass_ATTACH_evw
WHERE REL_OBJECTID = '51'
go

Results:

"�က䙊䙉Ā ĀĀ"

Is there a way to convert the BLOB into Base64?

Tags (2)
0 Kudos
2 Replies
DavidBuehler
Occasional Contributor III

Did you figure this out?

0 Kudos
TL2
by
Occasional Contributor III

Kind of.... I was able to get it to work but only with images the size of thumbnails.  Anything "large" would get cut off about 1 inches from the top.  

From what I read on the WWW it should work with normal sized images.  The string for a base64 is very large (but is under the varchar(max) limit)