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 null and then set them like below
ALTER PROCEDURE [dbo].[GetSummary] @PreviousStartDate NVARCHAR(50) , @PreviousEndDate NVARCHAR(50) , @CurrentStartDate NVARCHAR(50) , @CurrentEndDate NVARCHAR(50) AS BEGIN IF(@PreviousStartDate IS NULL OR EMPTY) SET @PreviousStartdate = '01/01/2010' for example..
I would appreciate the help.
Let's look at an example of how to use the IS NOT NULL condition in a SELECT statement in SQL Server. For example: SELECT * FROM employees WHERE last_name IS NOT NULL; This SQL Server IS NOT NULL example will return all records from the employees table where the last_name does not contain a null value.
The MySQL ISNULL() function is used for checking whether an expression is NULL or not. This function returns 1 if the expression passed is NULL, else it returns 0. The ISNULL() function accepts the expression as a parameter and returns an integer a value 0 or 1 depending on the parameter passed.
NULL is used in SQL to indicate that a value doesn't exist in the database. It's not to be confused with an empty string or a zero value. While NULL indicates the absence of a value, the empty string and zero both represent actual values.
I sometimes use NULLIF like so...
IF NULLIF(@PreviousStartDate, '') IS NULL
There's probably no reason it's better than the way suggested by @Oded and @bluefeet, just stylistic preference.
@danihp's method is really cool but my tired old brain wouldn't go to COALESCE when I'm thinking is null or empty :-)
Here is the general pattern:
IF(@PreviousStartDate IS NULL OR @PreviousStartDate = '')
''
is an empty string in SQL Server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With