Is there a way to exclude parts of a SQL Statement based on Declared Values?
DECLARE @OnlyY as VARCHAR(1) = 'Y'
SELECT count(*) from main where IDATE > '2016-01-01'
If @OnlyY = 'Y' THEN
AND Qualify = 'Y'
One option you can look into is
Dynamic SQL in which you can dynamically change anything you would need.
DECLARE @SQL AS NVARCHAR(MAX) SET @SQL = N'SELECT COUNT(*) FROM main WHERE IDATE > ''2016-01-01''' IF @OnlyY = 'Y' SET @SQL += N' AND Qualify = ''Y''' END IF EXECUTE sp_executesql @SQL