I'm trying to pass in a parameter and if the parameter is null I want to set the county Id to itself. If the county Id is not null, then I want to bring back records from all counties in the county collaboration.
I'm getting an incorrect syntax error. Any ideas on how to do this?
DECLARE @pCountyId as int;
select p.Id, p.LastName, p.FirstName, c.Id, c.Description
FROM Participant as p
INNER JOIN Application as a on p.Id = a.ParticipantId
INNER JOIN Dictionary.Counties as c on a.CountyId = c.Id
WHERE
If @pCountyId is null
BEGIN
c.Id = c.Id
END
ELSE
c.Id in (SELECT cc.CountyId
FROM CountyCollaboration as cc
WHERE cc.CollaborationId = (SELECT cc1.CollaborationId
FROM CountyCollaboration as cc1
WHERE cc1.CountyId = @pCountyId))