连接varbinary值并忽略null值?

时间:2017-06-07 21:33:31

标签: sql-server

以下代码

Schema::create('group_user', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id');
        $table->integer('group_id');
        $table->timestamps();

        $table->foreign('user_id')
                ->references('id')
                ->on('users'))
                ->onDelete('cascade');
        $table->foreign('user_id')
                ->references('id')
                ->on('users'))
                ->onDelete('cascade');
    });

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

以下代码返回null。

0x9069CA78E7450A285173431B3E52C5C25299E473

我尝试将null转换为0,但哈希值已更改。

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

连接时如何忽略空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 值?

1 个答案:

答案 0 :(得分:0)

您需要更改此Promise<V, Exception>来电的位置:

isnull()

我在SQL Server 2012中测试过它。