Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 布尔返回格_Sql Server_Sql Server 2008_Boolean_Case - Fatal编程技术网

Sql server 布尔返回格

Sql server 布尔返回格,sql-server,sql-server-2008,boolean,case,Sql Server,Sql Server 2008,Boolean,Case,我需要把两张桌子连接起来。如果b列为空,则连接将在c列上完成。如果不是,则连接将位于b列上 这是我需要的。但我怀疑我遗漏了什么,因为它的功能看起来有点复杂: select * from the_table t inner join another_table a on case when a.b = '' then case when t.c = a.c then 1 else 0 end else case when t.b = a.b then 1

我需要把两张桌子连接起来。如果b列为空,则连接将在c列上完成。如果不是,则连接将位于b列上

这是我需要的。但我怀疑我遗漏了什么,因为它的功能看起来有点复杂:

select *
from the_table t
inner join another_table a
   on
   case when a.b = '' then
      case when t.c = a.c then 1 else 0 end
   else
      case when t.b = a.b then 1 else 0 end
   end = 1
我遗漏了什么吗?

关于(a.b=''和t.c=a.c)或(a.b''和t.b=a.b)
ON (a.b = '' AND t.c = a.c) OR (a.b <> '' AND t.b = a.b)
ON(a.b=''和t.c=a.c)或(a.b''和t.b=a.b)