Eval() display custom value if null

前端 未结 5 1413
猫巷女王i
猫巷女王i 2021-01-25 02:51

    \' />

<
5条回答
  •  伪装坚强ぢ
    2021-01-25 03:12

    I will suggest to do it in SQL only:

    using ISNULL(expression, value_if_expression_is_null) or

    COALESCE(expression, expression2, expression3)
    

    example :

    SELECT
      Name, DOB,
      (CASE WHEN Address1 IS NULL THEN 'NA' ELSE Address1 END) AS Address1,
      (CASE WHEN Address2 IS NULL THEN 'NA' ELSE Address2 END) AS Address2,
      ...
    FROM Users
    

    or

    SELECT 
      Name, DOB, Address1, 
      coalesce(Address2,'NA'), coalesce(City,'NA'), 
      coalesce(State,'NA'), coalesce(Zip,'NA')
    FROM Users
    

提交回复
热议问题