0

尝试将 SQL 脚本从 SQL Server T-SQL 转换为 GCP BigQuery SQL,并且需要维护 ansi nulls 设置以确保相同的结果。有没有办法让 Google BigQuery 在比较 null = null 时返回 true(即下面的“null = null is true”)?

显示不同输出的 T-SQL 和 BigQuery 示例:

--GCP BigQuery test:
begin
declare null1 string;
declare null2 string;
select case when null1 = null2 then 'null = null is true' 
       else 'null = null is false'
       end as bqsqlnulltest;
end 

-- T-SQL (SQL Server) test:
set ansi_nulls off;
declare @null1 varchar(30);
declare @null2 varchar(30);
select case when @null1 = @null2 then 'null = null is true' 
else 'null = null is false'
end as tsqlnulltest;
4

1 回答 1

1

我不确定这到底适合您的查询。但是你可以使用这个结构:

where (x = y) is not false

或者在你的情况下:

where (null1 = null2) is not false
于 2021-07-02T20:15:47.363 回答