• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

DISTINCT KEYWORD for image data type column

how want to use distinct key word for image datatype in sql server
0
Kanigi
Asked:
Kanigi
  • 3
1 Solution
 
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
 
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now