我希望数据库表中包含NULL的列使其为空

时间:2014-03-20 05:52:36

标签: c# asp.net sql sql-server-2008

我在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

1 个答案:

答案 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