sql - Search Multiple Columns if parameters aren't null? -


i want search/filter on tables multiple parameters. want if send parameters 0 or null value, won't filter on column.

alter procedure [dbo].[search_load]     ,@name          nvarchar(200)        ,@user_id       int                  select                             [type]                 ,[record_id]                 ,[first_name]+space(1)+[last_name] full_name             [dbo].[process]                [name]     =   @name   ,            [user_id]  =   @user_id 

this proc. if send @name , @user_id, filter both; if send @user_id, must filter [user_id], or same other. if send @name = '' , @user_id = 0 should return unfiltered data. how can easily?

well, can use or clauses

i use @name only, in sample mix @name , @table_name

where   (coalesce(@name, '') = '' or [name] = @name)   ,   (coalesce(@user_id, 0) = 0 or [user_id] = @user_id) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -