2016-11-21 88 views
-2

我需要把一個條件,只得到CP7(郵政編碼),其中街道不是空Where條件的SQL Server

select top 1 cp7 
from codigospostais 
order by newid() 

我已嘗試添加一個WHERE條件,但它沒有工作(不正確的語法附近關鍵字'where'):

where street is not null 

你能幫助找到正確的方法來限制它嗎?

謝謝

+0

您不能在order by子句後面寫'where'。請嘗試先學習sql。這不是學習網站。 – Munavvar

回答

2

它來的from段之後和之前的order by部分:

select top 1 cp7 from codigospostais where street is not null 
4
select top 1 cp7 
from codigospostais 
where street is not null 
order by newid() 
0

不能使用其中ORDER BY子句後,試試這個

SELECT top 1 cp7 FROM codigospostais WHERE ISNULL(street,'') <> '' ORDER BY NEWID()