2013-05-25 19 views
0

我有一個SQL 2008表,其中列出了一堆文件的一些元數據如下:如何返回重複varbinary列

ID BIGINT 的FileName爲nvarchar(255) FileHash VARBINARY(512)

FileHash是FileName列中文件路徑的SHA-512散列。

我可以運行一個SELECT並返回具有相同FileHash的FileNames嗎?

+1

是否有您遇到的具體問題,或者您是否只希望有人爲您編寫查詢? – HABO

回答

1
declare @Nezbit as Table (Id BigInt Identity, FileName NVarChar(255), FileHash VarBinary(512)); 

insert into @Nezbit (FileName, FileHash) values 
    ('Bob', 0x1234), 
    ('Carol', 0x5678), 
    ('Ted', 0x9abc), 
    ('Alice', 0xdef0), 
    ('Robert', 0x1234), 
    ('Lydia', 0xdef0); 

select FileName, FileHash 
    from @Nezbit as N 
    where exists (select 42 from @Nezbit where FileHash = N.FileHash and Id <> N.Id) 
    order by FileHash, FileName;