declare @sSQL VARCHAR(2000)
SET sSQL='Select top 20 ID
FROM Prospects
WHERE p.StatusID not in (-1,2,4,5,6,7,8,9,12,13,14)'
+CASE WHEN @state IS NULL THEN '' ELSE CHAR(10) + 'AND P.State = '+ CHAR(39)[email protected] +CHAR(39) end
上面的代碼塊不返回任何狀態值,我想維護ISNULL功能。 原來的是有像這樣的where子句 - 'p.State = IsNull(@State,p.State)'使用case語句刪除我的SQL查詢中的ISNULL's
這就是Microsoft SQL Server語法。你爲什麼要標記這個問題[tag:mysql]? – 2014-09-24 17:53:01
coalesce比isnull更普遍'p.State = coalesce(@state,p.state)'? – xQbert 2014-09-24 17:57:24