sql - Convert Null to text on numeric field
问题描述
I have a query that LEFT joins 4 different tables. There will always be a match in one of these tables but we don't know which one. When the query is executed there are some fields producing NULL values. These are float fields but I was wondering if there is a way to change the Null to some kind of indicator such as "No Coverage"?
I have attempted something simple such as:
ISNULL(acccoverage, 'No Coverage') AS acccoverage
However when I run this I get the following error message:
Error converting data type varchar to float.
I'm sure its something simple but I have tried CONVERT and CAST but with no joy.
Thanks in advance
解决方案
First, use COALESCE()
. It is the standard function. Then convert the number to a string:
COALESCE(CONVERT(VARCHAR(255), acccoverage), 'No Coverage')
You can do the same thing with ISNULL()
.
推荐阅读
- javascript - 如何使用 Script Lab 使用 Microsoft Office JavaScript API 进行本地文件 I/O?
- regex - 正则表达式中“and”的重复
- excel - 根据用户输入生成行数
- insomnia - 失眠错误:使用制表符会导致不可预知的结果
- scikit-image - 试图从 skimage.feature 理解 match_template
- ios - Mapbox iOS SDK 使用多个文件
- python - 如何修复TypeError:'float'和'tuple'(CNN + Regr模型)的实例之间不支持'<'?
- sql - 找不到用于清除数据库的 DB2 存储过程
- java - 通过 java stacktrace 搜索 Datadog
- python - DMing 成员加入服务器 - Discord.Py