2017-06-07 10 views
0

次のコードvarbinary値を連結し、null値を無視しますか?

select hashbytes('SHA1', cast(a as varbinary(max))) FROM (select 0 a, null b) t 

戻る0x9069CA78E7450A285173431B3E52C5C25299E473

次のコードはnullを返します。

select hashbytes('SHA1', cast(a as varbinary(max)) 
    + cast(b as varbinary(max)) 
    + cast(c as varbinary(max)) 
FROM (select 0 a, null b, null c) t -- There may be many columns 

nullを0に変換しようとしましたが、ハッシュが変更されました。

select hashbytes('SHA1', cast(a as varbinary(max)) 
    + isnull(cast(b as varbinary(max)), 0)) 
    + isnull(cast(c as varbinary(max)), 0)) 
FROM (select 0 a, null b, null c) t 

連結時にNULL varbinaryの値を無視する方法はありますか?

答えて

0

あなたはこのようisnull()呼び出しの場所を変更する必要があります:

select hashbytes('SHA1', cast(isnull(a, '') as varbinary(max)) + cast(isnull(b, '') as varbinary(max)) + cast(isnull(c, '') as varbinary(max))) FROM (select 0 a, null b, null c) t;

は、私はSQL Serverでそれをテストしている2012年

関連する問題