tags:

views:

33

answers:

3

Hi Guys,

I'm having a lot of trouble writing a select statement to compare two values in t-sql which are of type image. This is what I have so far:

SELECT a.UserId, b.UserId
FROM [dbo].[aspnet_Profile] as a inner join [dbo].[aspnet_Profile] as b on
    (a.UserId = <some string> AND b.UserId = <some other string>)
WHERE BINARY_CHECKSUM(a.PropertyValuesBinary) = BINARY_CHECKSUM(b.PropertyValuesBinary)

But I keep getting error messages no matter what I do to the WHERE clause. For the above query, the error message I get is:

Error in binarychecksum. There are no comparable columns in the binarychecksum input.

At any rate, any help would be very much appreciated. I'm have a very hard time doing anything with this data-type, for some reason...

BTW: I'm using SQL Server Web (I think it's the 2008 edition)...

Thanks!

Andrew

A: 

Can you do this?

   select BINARY_CHECKSUM(A.PropertyValuesBinary) from aspnet_Profile as A

Knowing the #s of the error messages would help us help you.

Tim
Hi Tim, thanks for the idea. The error message I get with the above select statement is:
Andrew
Msg 8184, Level 16, State 1, Line 1Error in binarychecksum. There are no comparable columns in the binarychecksum input.
Andrew
A: 

You can't use binarychecksum on image types

BINARY_CHECKSUM ignores columns of noncomparable data types in its computation. Noncomparable data types include text, ntext, image, cursor, xml, and noncomparable common language runtime (CLR) user-defined types.

http://msdn.microsoft.com/en-us/library/ms173784.aspx

It might be easier to store a MD5 has along with the image. I can't imagine that you're getting good performance by requesting a binary_checksum of all of your images!

AdamH
Thanks for the tip, Adam. I'm using Sql Server Management Studio, and I just wanted to compare two values in a table. It's a one-off calculation, and itsn't really part of any code. Is there any way to do this in t-sql, without downloading any external implementations of MD5? Does t-sql implement MD5? I'm not really a DBA or anything...
Andrew
A: 

Take a look here

a1ex07
Why down vote ?
a1ex07
It's an unattributed link to a message board, with no commentary. Presumably the OP can use google for "Compare image SQL Server".
JNK
That post has the same problem discussed... Maybe he could use google, but it seems that he didn't. At least description of `BINARY_CHECKSUM` (as AdamH pointed) says that this function cannot be used with `image` type.
a1ex07
For what it's worth, a1ex07, I enjoyed reading and liked the link. It's informative, but I was hoping to compare the values using t-sql. It seems strange to me (and that's an understatement) that Microsoft would implement data types in sql server, and then give programmers no way to compare the values...
Andrew
I don't understand why you cannot compare images using `SUBSTRING(1, DATALENGTH(yourimagecolumn)` or first compare just ` DATALENGTH`, and then `SUBSTRING` if length is different...
a1ex07
@a1ex07 - edit and i'll remove it
JNK
@a1ex07, it worked, thanks. I thought I tried that already, but the substring function didn't seem to return anything. I must have fat-fingered something or just written the select statement incorrectly. Thanks for the help:)
Andrew