Declare @FarmName NVarChar
Set @FarmName = 'x'
If (SELECT Count(*) FROM [RDA Prod Pen Master] As pm LEFT JOIN (SELECT l.[Location ID],Farm,Convert(int, SubString(Convert(NVarChar, [Pen Scan]), 3, 4)) As [Pen Number] FROM [RDA Prod Pen Totals] As pt INNER JOIN Location As l ON Convert(int, SubString(Convert(NVarChar, [Pen Scan]), 1, 2)) = l.House) As totals ON pm.[Location ID] = totals.[Location ID] AND pm.[Pen Number] = totals.[Pen Number] INNER JOIN Location As l ON pm.[Location ID] = l.[Location ID] WHERE totals.[Location ID] Is Null AND l.Farm = @FarmName) = 0
BEGIN
Print 'Inside the BEGIN'
END
ELSE
Print 'Inside the ELSE'
|