我想实现如下功能:

 where
 case  when (@a = null) 
     then 1 = 1
     else @a=a
and b=@b

但是这样报错,经过翻阅资料找到如下解决方案:

 where
(1 = (CASE WHEN @a IS NULL THEN 1 ELSE 0 END)
OR  a=@a )
AND b=@b

测试得知,当1=1时不执行后面的a=@a,反之执行。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2021-07-14
  • 2021-11-22
  • 2021-11-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案