On SQL Server I am trying to be able to select * records from a table with four parameters, in some cases the incoming parameter will be a certain string value 'Select', in that case I would like to select * from the specified field.
Does anyone know of a good way to handle this?
(
@mParameter varchar(50) = Null,
@tParameter varchar(50) = Null,
@gParameter int = Null,
@nParameter varchar(255) = Null
)
as
Select
*
From
TableA
Where
If @mParameter = 'Select' then
M = @mParameter
If @tParameter = 'Select' then
AND
T = @tParameter
If @gParameter = 'Select'then
AND
G = @gParameter
If @nParameter = 'Select' then
AND
N = @nParameter