I have a store procedure with many conditions but one of them depend of the value of one of my parameter. At the moment I'm using if statement and duplicate query, I want to improve but I can't find other way. some idea how
MyStoreProcedure Code
If @paramstate = 'All'
Select mytable.field1, mytable.field2, mytable.field3, mytable.field4,mytable.field5
from mytable
Where mytable.field6 is null
and mytable.field1 is not null
Else
Select mytable.field1, mytable.field2, mytable.field3, mytable.field4,mytable.field5
from mytable
Where mytable.field6 is null
and mytable.field1 is not null
and mytable.state = @paramstate
End
how can I improve it?