如何在SQL Server 2008中使用TO_Char()

时间:2014-08-25 13:28:04

标签: sql-server sql-server-2008

我正在尝试将SQL语句转换为SQL Server 2008.那么我该怎么做呢?下面是我要转换的sql语句。我也尝试从Stackoverflow问题解决,但我没有成功How to use TO_CHAR function functionality

SELECT 
    C_Debt_Payment.AD_Client_ID,  
   (CASE WHEN C_Debt_Payment.AD_Client_ID IS NULL THEN '' 
         ELSE (COALESCE(TO_CHAR(TO_CHAR(COALESCE(TO_CHAR(table1.Name), ''))),'') ) END) AS AD_Client_IDR

感谢您的回复和评论

1 个答案:

答案 0 :(得分:1)

TO_CHAR是Oracle。在SQL Server中,使用CONVERT

SELECT C_Debt_Payment.AD_Client_ID,  
  (CASE WHEN C_Debt_Payment.AD_Client_ID IS NULL THEN '' ELSE COALESCE(CONVERT(varchar(20),table1.name),'') END) AS AD_Client_IDR