I know how to check if a parameter is null but i am not sure how to check if its empty ... I have these parameters and I want to check the previous parameters are empty or n
Here is the general pattern:
IF(@PreviousStartDate IS NULL OR @PreviousStartDate = '')
''
is an empty string in SQL Server.
I recommend checking for invalid dates too:
set @PreviousStartDate=case ISDATE(@PreviousStartDate)
when 1 then @PreviousStartDate
else '1/1/2010'
end
You can try this:-
IF NULLIF(ISNULL(@PreviousStartDate,''),'') IS NULL
SET @PreviousStartdate = '01/01/2010'
To check if variable is null or empty use this
IF(@PreviousStartDate IS NULL OR @PreviousStartDate = '')
Another option:
IF ISNULL(@PreviousStartDate, '') = '' ...
see a function based on this expression at http://weblogs.sqlteam.com/mladenp/archive/2007/06/13/60231.aspx
If you want a "Null, empty or white space" check, you can avoid unnecessary string manipulation with LTRIM
and RTRIM
like this.
IF COALESCE(PATINDEX('%[^ ]%', @parameter), 0) > 0
RAISERROR ...