我有一个县参数,如果它为空,那么我想选择协作中的所有县,如果它不为空,那么我只想要那个县的值。如何IF
正确设置语句?声明的第一部分IF
可能会带回多个县 ID,这就是我输入的原因WHERE CountyId
。
SELECT a.CountyId, co.Description as County
FROM Application as a
INNER JOIN Dictionary.Counties as co on a.CountyId = co.Id
WHERE co.Id in
IF @pCountyId is null then
BEGIN
SELECT cc1.CountyId
FROM CountyCollaboration as cc1
WHERE cc1.CollaborationId = (SELECT cc2.CollaborationId
FROM CountyCollaboration as cc2
WHERE cc2.CountyId = @pHiddenCountyId)
END
ELSE
BEGIN
SELECT @pCountyId
END