SQL如何根据传入的参数来判断是否执行where条件 存储过程

SQL如何根据传入的参数来判断是否执行where条件 存储过程怎么写的

Create Procedure [test]
@strwhere varchar(200)="" --c查询条件

as

declare @strSql varchar(500)-- 主语句

begin

if(@strwhere!="")
bengin
set @strSql="select * from tablename where "+@strwhere

else

set @strSql="select * from tablename ";
end
end
exec ( @strSql)