我正在爲一些外部系統創建視圖。這個外部系統不能處理空值,所以我想通過例子「」來改變它們,使其更加用戶友好。基於JOIN兩個表的SQL Server視圖 - 如何用空格替換NULL值?
我用這個查詢創建我的觀點:
CREATE VIEW SomeView
AS
SELECT
r.CountryRegionCode, r.Name, e.ExampleData
FROM
AdventureWorks2008.Person.CountryRegion r
JOIN
AdventureWorks2008.dbo.SomeTable e ON r.CountryRegionCode = e.CountryRegionCode
此查詢的結果是:
按我的理解,我可以使用ISNULL運營商與空間來代替NULL,但如何在我的聲明中使用它?如何正確操作:
SELECT
ISNULL (r.CountryRegionCode, 0) AS r.CountryRegionCode
-- ..
?
更新:它不理解r
是什麼:
更新#2:感謝你們非常感謝!最終的結果是:
SELECT
CountryRegionCode = ISNULL(r.CountryRegionCode, ''),
Name = ISNULL(r.Name,''),
ExampleData = ISNULL(e.ExampleData,'')
FROM
AdventureWorks2008.Person.CountryRegion r
JOIN
AdventureWorks2008.dbo.SomeTable e ON r.CountryRegionCode = e.CountryRegionCode
這是對你合適: SELECT ISNULL(r.CountryRegionCode, '')AS CountryRegionCode –