Image Retrieval From DB

we are trying to get the blob image which is stored in the MSSQL database.we used the code given below for selecting the image from the database.
however we are not getting the desired result.Please help us in retrieving images from database and exhibiting in perspective.

SELECT CAST(’’ as xml).value(‘xs:base64Binary(sql:column("defect_image))’, ‘varbinary(MAX)’)
FROM Defect_image
WHERE Defect = :myValueX

script to transform

image = “data:imagef;base64,%s”%value

return Image