我在 sql server 2008 中创建了一个存储过程,其中显示同一数据库中两个不同表的列。我想将列中的 NULL 值替换为空白。有人可以帮我吗?
AlTER PROCEDURE sp_Test123 --sp_Test123
AS
BEGIN
SELECT MediaContentType.MediaContentTypeID as ID,
MediaContentType.FileExtension,
IQCategory.Description,IQSubCategory.IQSubDesription
FROM MediaContentType
LEFT JOIN IQCategory
ON MediaContentType.MediaContentTypeID =IQCategory.IQCategoryID
LEFT JOIN IQSubCategory
ON MediaContentType.MediaContentTypeID = IQSubCategory.IQSubCategoryID
END
最佳答案
如果您需要替换查询中的 Null
值,那么这非常简单。
您必须使用IsNull
函数。
喜欢
SELECT MediaContentType.MediaContentTypeID as ID,
ISNULL(MediaContentType.FileExtension,'') as FileExtension,
ISNULL(IQCategory.Description,'') as Description
ISNULL(IQSubCategory.IQSubDesription,'') as IQSubDesription
FROM MediaContentType
LEFT JOIN IQCategory
ON MediaContentType.MediaContentTypeID =IQCategory.IQCategoryID
LEFT JOIN IQSubCategory
ON MediaContentType.MediaContentTypeID = IQSubCategory.IQSubCategoryID
如果您想更新表中的空值,请使用更新语句。
喜欢
Update MyTable
Set MyNullColumn = ''
where MyNullColumn Is Null
关于c# - 我希望数据库表中具有 NULL 的列将其设为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22524507/