且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 SQL Server 中将图像数据类型转换为字符串

更新时间:2023-01-30 19:11:15

您可以通过 for xml path() 运行将图像值提取为 BASE64.

You can extract the image value as BASE64 by running it through for xml path().

试试:

select 'empphoto : '+(select empphoto as '*' for xml path(''))

结果看起来像这样.

empphoto : /9j/4AAQSkZJRgABAQAAAQABAAD/wAARCADw

相反,您必须删除前 11 个字符 (empphoto :),转换为 XML 并将值提取为 varbinary(max)..

To go the other way you have to remove the first 11 characters (empphoto :), cast to XML and extract the value as varbinary(max)..

select cast(stuff(YourTextColumn, 1, 11, '') as xml).value('.', 'varbinary(max)')