Have been using Stored procedures for at least a year now to carry out search functionality by quering few tables. All working as expected.
When I started writing my first SP, have used some code from other SPs out there on Internet. Now I feel that I should be knowing the reasons behind writing certain statements in SP.
Your valid reason behind each of this statement is appreciated. Questions are posed as comments in below SP.
ALTER Procedure [dbo].[PRO_spSearchUsers]
@username nvarchar(256) = NULL,
@id nvarchar(256) = NULL,
@userid nvarchar(20) = NULL,
@country nvarchar(50) = NULL,
@department nvarchar(100) = NULL,
@email nvarchar(100) = NULL,
@status nvarchar(4000) = NULL,
@Resources nvarchar(50) = NULL
) AS BEGIN
--Question 1:- Why this statement is required?
If @username IS NOT NULL and Len(@username)=0 Set @username = NULL
If @id IS NOT NULL and Len(@id)=0 Set @id = NULL
If @userid IS NOT NULL and Len(@userid)=0 Set @userid = NULL
If @country IS NOT NULL and Len(@country)=0 Set @country = NULL
If @department IS NOT NULL and Len(@department)=0 Set @department = NULL
If @email IS NOT NULL and Len(@email)=0 Set @email = NULL
If @status IS NOT NULL and Le
View Complete Post