Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

case statement

Status
Not open for further replies.

rds80

Programmer
Nov 2, 2006
124
0
0
US
I realized a bit late that the code below doesn't work. If there is an assistant manager, but no manager I still get a blank and that is incorrect.

Code:
COALESCE(dbo.udfGetManager(CM.ControlID) + ', ' + dbo.udfGetAssistantManager(CM.ControlID), '')

So this is the replacement code:

Code:
CASE WHEN MIN(dbo.udfGetManager(CM.ControlID)) IS NULL THEN CASE WHEN MIN(dbo.udfGetAssistantManager(CM.ControlID)) IS NULL THEN ''
ELSE MIN(dbo.udfGetAssistantManager(CM.ControlID)) END
WHEN MIN(dbo.udfGetManager(CM.ControlID)) IS NOT NULL THEN CASE WHEN MIN(dbo.udfGetAssistantManager(CM.ControlID)) IS NULL THEN MIN(dbo.udfGetManager(CM.ControlID))
ELSE MIN(dbo.udfGetManager(CM.ControlID)) + ', ' + MIN(dbo.udfGetAssistantManager(CM.ControlID)) END
END

I tested it out and it seems to take care of all the different situations. But just wanted to make sure with you guys. Thanks.
 
So... if there is no manager, you want to display the assistant manager? If there is neither, then you want to show an empty string? The Coalesce function can handle that for you. Like this...

[tt][blue]
COALESCE(NullIf(dbo.udfGetManager(CM.ControlID), '') + ', ' + dbo.udfGetAssistantManager(CM.ControlID),
dbo.udfGetAssistantManager(CM.ControlID),
'')

[/blue][/tt]

This may not be perfect. What return value to get you from the functions if the manager or assitant does not exist? Anyway, give it a try.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top