Solved

SQL Nested Case Select Help

Posted on 2011-03-23
3
474 Views
Last Modified: 2012-05-11
, Trying to a nested case

See code below..Cant get it to work            
CASE 
     WHEN @LoginAgentClient ='Agent' 
       and	dbo.ufn_User_RetrieveCount_UniqueView_v000101(l.ListID,@LoginID,@UserGroupID,100001)>0 
        THEN 'Y'
    ELSE
      CASE
        WHEN @LoginAgentClient ='Client'
          THEN Null
     ELSE  'N'	            				
       END AS  CountListViewed,

Open in new window

0
Comment
Question by:cheryl9063
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 500 total points
ID: 35202702
Try this:
CASE
     WHEN (@LoginAgentClient ='Agent')
       and      (dbo.ufn_User_RetrieveCount_UniqueView_v000101(l.ListID,@LoginID,@UserGroupID,100001)>0) THEN 'Y'
    ELSE (CASE
                   WHEN (@LoginAgentClient ='Client') THEN Null
                   ELSE  'N' END) END) AS  CountListViewed,
0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 35202775
BTW yours is correct you just forgot one END:
CASE
     WHEN @LoginAgentClient ='Agent'
       and      dbo.ufn_User_RetrieveCount_UniqueView_v000101(l.ListID,@LoginID,@UserGroupID,100001)>0
        THEN 'Y'
    ELSE
      CASE
        WHEN @LoginAgentClient ='Client'
          THEN Null
     ELSE  'N'                                          
       END END AS  CountListViewed,
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 35202808
What's the sense in trying to nest cases? You can use this syntax without nesting instead:
case
   when @LoginAgentClient ='Agent' and     dbo.ufn_User_RetrieveCount_UniqueView_v000101(l.ListID,@LoginID,@UserGroupID,100001)>0
             then 'Y'
   when @LoginAgentClient ='Client'
             then NULL
   else 'N' end as CountListViewed

Open in new window

or even better
case @LoginAgentClient 
   when 'Agent' and     dbo.ufn_User_RetrieveCount_UniqueView_v000101(l.ListID,@LoginID,@UserGroupID,100001)>0
             then 'Y'
   when 'Client'
             then NULL
   else 'N' end as CountListViewed

Open in new window

0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question