如何在T-Sql中自定义结果

如何在T-Sql中自定义结果,sql,tsql,Sql,Tsql,我的部分SQL代码如下所示。如果未找到符合特定条件的记录,我想知道如何将“未找到记录”移动到BankAccountCode。使用合并函数返回第一个非空值 (SELECT DISTINCT RTRIM(CB_Account_Code) FROM Correspondent_Bank WHERE Correspondent_Bank.CB_Cnt_Code = Contributions.Con_Cnt_Code and

我的部分SQL代码如下所示。如果未找到符合特定条件的记录,我想知道如何将“未找到记录”移动到BankAccountCode。

使用
合并
函数返回第一个非空值

           (SELECT DISTINCT RTRIM(CB_Account_Code)
            FROM Correspondent_Bank
                 WHERE Correspondent_Bank.CB_Cnt_Code = Contributions.Con_Cnt_Code and
                       Correspondent_Bank.CB_Prv_Code = Contributions.Con_Prv_Code and
                       Correspondent_Bank.CB_Dst_Code = Contributions.Con_Dst_Code and
                       Correspondent_Bank.CB_Cor_Code = Contributions.Con_Cor_Code) as BankAccoutCode

不清楚你在问什么。请添加示例数据,以解释您要在此处执行的操作。您是否有一些应用程序来显示此数据?然后,它可以更好地在那里处理,而不是在sql中处理
select COALESCE( (SELECT DISTINCT RTRIM(CB_Account_Code)
                FROM Correspondent_Bank
                     WHERE Correspondent_Bank.CB_Cnt_Code = Contributions.Con_Cnt_Code and
                           Correspondent_Bank.CB_Prv_Code = Contributions.Con_Prv_Code and
                           Correspondent_Bank.CB_Dst_Code = Contributions.Con_Dst_Code and
                           Correspondent_Bank.CB_Cor_Code = Contributions.Con_Cor_Code) ,'NO RECORDS FOUND') as BankAccoutCode