SQL Server : IF null 替换为其他列数据

SQL Server : IF null Replace with other column data

我真的是 SQL 服务器的新手。我想用同一 table.

中另一列的数据替换空列
Declare @ref As mgr.gl_jlhdr.ref_no
Declare @P_no As mgr.gl_jlhdr.jlno

IF ref = Null
Then ref = P_no
end if

请帮忙。

我收到一个错误

The type name 'mgr.gl_jlhdr.ref_no' contains more than the maximum number of prefixes. The maximum is 1.

我想要的是用其他列数据替换空值列。

示例

如果 reference_no 为空,我希望它使用 Product_no 数据。

在查询中,您可以使用 coalesce():

select coalesce(reference_no, product_no)
from mgr.gl_jlhdr;