Q:

IF..ELSE Logic in stored procedure

I have a stored procedure where I need to pull data from a table column based on an input parameter.
If the input parameter is 'Y' I need to pull only 'Y' values from the table column, if it is 'N', I need to pull all values irrespective of 'Y' or 'N' or NULL.

A:

While this can be expressed as an if...else condition, it can also be expressed as a simple OR:
SELECT <ColumnsList> 
FROM <TableName>
WHERE <Column> = @Param
OR @Param = 'N'

Please note that this approach doesn't prevent you to get all the data from the table where <Column> contains 'P', for example - because the value of @Param can be anything.
If you want only 'Y' and 'N', you should add another condition:
SELECT <ColumnsList> 
FROM <TableName>
WHERE (
    <Column> = @Param
    AND @Param = 'Y'
)
OR @Param = 'N'

With this query, any value of @Param other than 'Y' or 'N' will not return anything from the table.

