DISTINCT KEYWORD for image data type column

how want to use distinct key word for image datatype in sql server
KanigiAsked:
Who is Participating?
 
Anthony PerkinsCommented:
You have a couple of options:
1.  As alluded to previously, use the HASHBYTES() function to get a hash of the image.
2. Use the undocumented function fn_varbintohexstr as in:
SELECT DISTINCT master.dbo.fn_varbintohexstr(YourColumnName)
FROM YourTableName

Both options have the caveat that they will only consider the first 8000 bytes.
0
 
jonaskaCommented:
I would suggest calculating a checksum for the data, and select distinct on that. Maybe you can use a managed function to calculate the checksum?
0
 
KanigiAuthor Commented:
What is meant by calculating a checksum?
0
 
jonaskaCommented:
I thought of SHA1 or MD5 over the Image data.

In the below example MyManagedFucntion could simply return the checksum for the data in MyImageColumn.

SELECT MAX(idCol), dbo.MyManagedFucntion(MyImageColumn)  FROM myTable
GROUP BY dbo.MyManagedFucntion(MyImageColumn)

Open in new window

0
 
jonaskaCommented:
Maybe this will explain better: http://en.wikipedia.org/wiki/Checksum
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.