2016-07-17 69 views
0

我做了一個INNER在存儲過程中加入,但我不知道該怎麼把我的WHERE子句來過濾那些具有空值的列,只顯示那些在特定列上不爲空的行。我做的存儲過程,但我不知道該怎麼把我的WHERE子句來過濾空列

CREATE PROCEDURE [dbo].[25] 
@param1 int 
AS 
    SELECT c.Name, c.Age, c2.Name, c2.Country 
    FROM Cus C 
    INNER JOIN Cus2 C2 ON c.id = c2.id 
    WHERE c2.country is not null and c2.id = @param1 
    Order by c2.Country 
RETURN 0 

ID 1

+-----+----+---------+---------+ 
| QID | ID | Name | Country | 
+-----+----+---------+---------+ 
| 1 | 1 | Null | PH  | 
| 2 | 1 | Null | CN  | 
| 3 | 1 | Japhet | USA  | 
| 4 | 1 | Abegail | UK  | 
| 5 | 1 | Norlee | Ger  | 
+-----+----+---------+---------+ 

ID 2

+-----+----+----------+---------+ 
| QID | ID | Name | Country | 
+-----+----+----------+---------+ 
| 1 | 2 | Null  | PH  | 
| 2 | 2 | Null  | CN  | 
| 3 | 2 | Reynaldo | USA  | 
| 4 | 2 | Abegail | UK  | 
| 5 | 2 | Norlee | Ger  | 
+-----+----+----------+---------+ 

ID 3

+-----+----+----------+---------+ 
| QID | ID | Name | Country | 
+-----+----+----------+---------+ 
| 1 | 3 | Gab  | PH  | 
| 2 | 3 | Null  | CN  | 
| 3 | 3 | Reynaldo | USA  | 
| 4 | 3 | Abegail | UK  | 
| 5 | 3 | Norlee | Ger  | 
+-----+----+----------+---------+ 

我想,當我所選擇的任何用戶的在C表將顯示C子表數據並刪除空名稱行並保留具有非空名稱列的行。

所需的結果:

Ç表(父)

+----+---------+-----+ 
| ID | Name | Age | 
+----+---------+-----+ 
| 3 | Abegail | 31 | 
+----+---------+-----+ 

C2表(兒童)

+-----+----+----------+---------+ 
| QID | ID | Name | Country | 
+-----+----+----------+---------+ 
| 1 | 3 | Gab  | PH  | 
| 3 | 3 | Reynaldo | USA  | 
| 4 | 3 | Abegail | UK  | 
| 5 | 3 | Norlee | Ger  | 
+-----+----+----------+---------+ 

回答

0

解決方案1:試驗不爲空值

實施例:

WHERE yourcolumn IS NOT NULL 

解決方案2:在你的where子句(comparaison。減去空值)測試comparaison值

實例:

WHERE yourcolumn = value 
    WHERE yourcolumn <> value 
    WHERE yourcolumn in (value) 
    WHERE yourcolumn not in (value) 
    WHERE yourcolumn between value1 and value2 
    WHERE yourcolumn not between value1 and value2 
+0

WHERE yourcolumn <> value是我所需要的。感謝:D –

4

WHERE column IS NOT NULL是濾除NULL值的語法。

+0

它沒有過濾掉空列。 –

+0

它確實是'NULL'還是隻是一個包含''null''的標準文本字符串?如果是後者,你只需要比較'column <>'null'' – Aganju

+0

好的,先生。謝謝。我會再次嘗試:d –