我正在使用 SQL Server 2008 Express,并且我有一个SELECT基于参数执行来自表的存储过程。我有nvarchar参数和int参数。
这是我的问题,我的 where 子句如下所示:
WHERE [companies_SimpleList].[Description] Like @What
AND companies_SimpleList.Keywords Like @Keywords
AND companies_SimpleList.FullAdress Like @Where
AND companies_SimpleList.ActivityId = @ActivityId
AND companies_SimpleList.DepartementId = @DepartementId
AND companies_SimpleList.CityId = @CityId
这个参数是我的 ASP.NET MVC 3 应用程序的用户设置的过滤器值,int可能没有设置参数,所以它们的值会是 0。这是我的问题,存储过程会搜索有0asCityId的项例如,为此,它返回错误的结果。因此,如果能够根据 int 参数的值是否大于 0,能够有一个动态的 where 子句,那就太好了。
提前致谢