SQLUSA

Microsoft SQL Server 2005 Best Practices

 

How to retrieve photos with varbinary(max) data type?

 

Execute the following script in Query Editor to retrieve a product photo using varbinary(max) column type:

USE AdventureWorks;

CREATE FUNCTION Production.fnProductPhoto (@ProductID int)
RETURNS varbinary(MAX)
AS
BEGIN
DECLARE @Photo varbinary(max)
SELECT @Photo = pp.LargePhoto
FROM Production.ProductPhoto AS pp
INNER JOIN Production.ProductProductPhoto ppp
ON pp.ProductPhotoID = ppp.ProductPhotoID
WHERE ppp.ProductID = @ProductID
RETURN @Photo
END
GO
SELECT Production.fnProductPhoto(1)
GO


 

The World Leader in SQL Server Training
 
 
SQLUSA.com Home Page