Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Stored Image in sql table using sql server 2005.Now I need to check Whether the image already exists or not.
My Code is Below

What I have tried:

SQL
CREATE PROCEDURE sptblEmployeeProofDetail
(
@SID numeric(18),@EmpSid numeric(18),@ProofTypeSID numeric(18),@ProofNo nvarchar(50),
@ProofPath nvarchar(100),@ProofImage image,@RevisionNo numeric(18),@CreatedBy numeric(18,3))
AS 
BEGIN

IF ((Select Count(*) from tblEmployeeProofDetail where EmpSid=@EmpSid and ProofTypeSID=@ProofTypeSID
     and ProofPath=@ProofPath and ProofImage=@ProofImage)>0)
BEGIN
 Select Top 1  @RevisionNo = RevisionNo +1 from tblEmployeeProofDetail order by RevisionNo Desc
END
INSERT INTO tblEmployeeProofDetail
(EmpSid,ProofTypeSID,ProofNo,ProofPath,ProofImage,RevisionNo,CreatedBy,CreatedOn)
VALUES
(@EmpSid,@ProofTypeSID,@ProofNo,@ProofPath,@ProofImage,@RevisionNo,@CreatedBy,GETDATE())
END


The Error Message is
Msg 402, Level 16, State 1, Procedure sptblEmployeeProofDetail, Line 9
The data types image and image are incompatible in the equal to operator.
Posted
Updated 17-Sep-18 0:43am
v3
Comments
Richard MacCutchan 17-Sep-18 6:04am    
The message is clear, there is an incompatibility between the type in your stored procedure and the one in your database table.
phil.o 17-Sep-18 6:13am    
Not exactly :) It tells that you cannot compare image datatype using equal to operator.
[no name] 17-Sep-18 6:16am    
Yes.Now How can i Check whether image is exists are not in table using sql storedprocedure
Maciej Los 17-Sep-18 6:28am    
Good point!
Richard MacCutchan 17-Sep-18 6:46am    
So what is the answer?

In addition to the change to VARBINARY suggested by 0x01AA, I'd suggest that you don't use it in the WHERE clause, although it will work. Instead, add an extra column to you table containing a Hash value (MD5 or a basic SHA will do for this, there is no need to be secure) and compare the hash values instead of the image itself.

Since images tend to be pretty large, once your DB gets populated, that SELECT will start to run slower and slower if you continue to compare images. Comparing hashes is a lot quicker, as they are a defined - much smaller - size. If you are feeling paranoid, you can compare the images if you get hash matches, but it probably isn't needed.
 
Share this answer
 
Well, the only way to compare images on SQL server side is to CONVERT[^] them into VARBINARY data type:
SQL
...
WHERE CONVERT(VARBINARY(MAX), ProofImage) = CONVERT(VARBINARY(MAX), @ProofImage)


Note: i'm not sure that CONVERT fuction is available on MS SQL Server 2005, because of MSDN documentation...

For further details, please see: SQL Server 2005 Data Types Reference - ConnectionStrings.com[^]
 
Share this answer
 

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