Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DISTINCT KEYWORD for image data type column

Posted on 2011-03-08
6
Medium Priority
?
469 Views
Last Modified: 2012-06-27
how want to use distinct key word for image datatype in sql server
0
Comment
Question by:Kanigi
  • 3
5 Comments
 
LVL 6

Expert Comment

by:jonaska
ID: 35068620
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
 

Author Comment

by:Kanigi
ID: 35068628
What is meant by calculating a checksum?
0
 
LVL 6

Expert Comment

by:jonaska
ID: 35068669
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
 
LVL 6

Expert Comment

by:jonaska
ID: 35068679
Maybe this will explain better: http://en.wikipedia.org/wiki/Checksum
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 35069188
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question