我在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
答案 0 :(得分:4)
如果您需要在查询中替换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语句。
像
Update MyTable
Set MyNullColumn = ''
where MyNullColumn Is Null