Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have one new R&D task for my own project.

i have on table with column
auto_id (int identity), Catelog_Id (int) , CatelogImage (Image datatype)

and this table have around 20,000 rows in table.

now i want to find duplicate image from this table. than how is it possible? how can i do it? want to get auto_Id whose have same image in it.

--- What i have tried until now ---
Tried Distinct :
Error : The image data type cannot be selected as DISTINCT because it is not comparable.
Article : http://support.microsoft.com/kb/162032/en-us[^]

Tried by converting in to varbinary(max) and distinct:
not getting right solution because i thing varbinary datatype has limit like varchar(8000).

Please help if anybody have done this type of R&D.
Posted

1 solution

Hi,

The main idea is to compare hash bytes with 'md5' algorithm.
I have create table like your columns

create table emp (auto_id int identity(1,1), Catelog_Id int, CatelogImage Image) 


Next i have populate with script (running many times) :

SQL
Insert emp (Catelog_Id, CatelogImage)
Select 1001, BulkColumn from Openrowset( Bulk 'D:\CodeProject1.jpg', Single_Blob)
Insert emp (Catelog_Id, CatelogImage)
Select 1001, BulkColumn from Openrowset( Bulk 'D:\CodeProject2.jpg', Single_Blob)
Insert emp (Catelog_Id, CatelogImage)
Select 1001, BulkColumn from Openrowset( Bulk 'D:\CodeProject3.jpg', Single_Blob)


finally to list all id's for the same image, run this script :

;
with hashimage (
	hashimage_hash
	,hashimage_count
	)
as (
	select hashbytes('md5', cast([catelogimage] as varbinary)),count(*)
	from emp
	group by hashbytes('md5', cast([catelogimage] as varbinary))
	having count(*) > 1
	)
select hashimage_hash
	,stuff((
			select ',' + rtrim(auto_id)
			from emp sub
			where hashbytes('md5', cast([catelogimage] as varbinary)) = hashimage_hash
			for xml path('')
			), 1, 1, '')
from hashimage


Source :
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d55317cc-8bff-4e7d-a34c-f75da7e4778b/how-to-compare-imagevarbinary-column[^]
 
Share this answer
 
Comments
desaihardikj@gmail.com 12-Sep-15 2:24am    
Thanks for reply,
I tried this algorithm but its not giving correct output of image match. :'(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900