Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
I know this is going to be easy to all of you, this is my first time performing an if else statement in SQL,
after performing this query:
IIf(IsNull(EventSummary.[Event Information - Event Status]),"ACTIVE",EventSummary.[Event Information - Event Status]) AS [Event Status],


I get this error message:
Msg 174, Level 15, State 1, Line 2
The isnull function requires 2 argument(s).


I just want to perform a query that will select the event status, check if it is null, if it is null, then value of event status should be active, else, just copy the value of event status.

I hope you can help me.
Thanks.
Posted

Dear it contains 2 arguments....

VB
ISNULL ( check_expression , replacement_value )

SQL
check_expression
    Is the expression to be checked for NULL. check_expression can be of any type.
replacement_value
    Is the expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expresssion.
 
Share this answer
 
Comments
serigraphie 28-Jul-11 10:00am    
Hi, I truly appreciate your reply, so you mean my code does not supply two argumanets needed?
Thank you so much
I think you're confusing the ISNULL() function with IS NULL

The former will do the replacement for you ISNULL(eventInfo,"ACTIVE") the latter gives a boolean result and could be used in your IF statement
 
Share this answer
 
Comments
serigraphie 28-Jul-11 10:01am    
so there is another function called "is null" which is different than "ISNULL()" functions?
you would use the isnull() function to replace the null values from your query with a default value. for example

VB
create table #temp
(
 IntValue int
)

insert into #temp values (0)
insert into #temp values (1)
insert into #temp values (2)
insert into #temp values (null)
insert into #temp values (3)

select IntValue
from #temp

select isnull(IntValue,-100)
from #temp


what I think your after is something like this

SQL
declare @value int
set @value = null

if @value is null then
 print 'Value is nothing'
end if


Hope this clears up the different definitions of is null
 
Share this answer
 
v2
Comments
Manas Bhardwaj 28-Jul-11 11:18am    
nicely done. +5
Simon_Whale 28-Jul-11 11:35am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900