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:

Collapse | Copy Code
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. .

Recommended Answers

All 4 Replies

Maybe something along these lines rather?

SELECT (CASE WHEN COALESCE((EventSummary.[Event Information] - EventSummary.[Event Status]),0) = 0 THEN 'ACTIVE' ELSE (EventSummary.[Event Information] - EventSummary.[Event Status]) END) AS [Event Summary]

I'm guessing that your field is EventSummary.[Event Information - Event Status], so I'll suggest

isnull(EventSummary.[Event Information - Event Status],'ACTIVE')

This in SQL will instruct the server to check if the field is null and if it is return ACTIVE. If the field is not null the it will return the value in the field.

PS: Have you googled isnull?

commented: added 1 for you! great answer! +1

I'm guessing that your field is EventSummary.[Event Information - Event Status], so I'll suggest

isnull(EventSummary.[Event Information - Event Status],'ACTIVE')

This in SQL will instruct the server to check if the field is null and if it is return ACTIVE. If the field is not null the it will return the value in the field.

PS: Have you googled isnull?

That solved my problem, thanks a ton!

Done adding reputation :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.