Dealing with parameter when it send null or with value normally we user condition like this
WHERE (user_name = @user_name OR @user_name IS NULL )
There is sql function that do this thing smartly called COALESCE
WHERE (user_name = COALESCE(@user_name,user_name)
Above where clause is same as the we are using COALESCE.For further user of COALESCE read this article its very usefull.
Reference :
http://www.sqlbook.com/sql-string-functions/sql-coalesce/
WHERE (user_name = @user_name OR @user_name IS NULL )
There is sql function that do this thing smartly called COALESCE
WHERE (user_name = COALESCE(@user_name,user_name)
Above where clause is same as the we are using COALESCE.For further user of COALESCE read this article its very usefull.
Reference :
http://www.sqlbook.com/sql-string-functions/sql-coalesce/
No comments:
Post a Comment