返回空值而不是“未更新”#39;

时间:2016-09-12 06:16:33

标签: sql sql-server sql-server-2008 tsql

DECLARE

SELECT  top 1 'Uploaded_Date' =   
 CASE isnull(Uploaded_Date,'')  
 WHEN Uploaded_Date THEN 'NOT UPDATED' 
else uploaded_date 
  END     
FROM ABC

当Uploaded_date列为null或为空时,它应该返回NOT UPDATED,而是返回NULL ..!

先谢谢

2 个答案:

答案 0 :(得分:0)

尝试使用以下查询。

   SELECT  top 1 
   CASE WHEN (Uploaded_Date IS NULL or LTRIM (RTRIM (isnull(Uploaded_Date,'')))='NULL')
        THEN CAST('NOT UPDATED' AS VARCHAR(50))
        ELSE CAST(uploaded_date AS VARCHAR(50)) END  as  'Uploaded_Date'
     FROM ABC

答案 1 :(得分:0)

您正尝试将int值设置为Uploaded_Date varchar(50)。而不是存储int 0存储'0',即varchar并在case语句中进行比较。它应该可以工作。

   SELECT  top 1 'Uploaded_Date' =   
     CASE isnull(Uploaded_Date,'0')  
     WHEN '0' THEN 'NOT UPDATED' 
    else uploaded_date 
      END     
    FROM ABC