Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Case on Return no records/no results

Author  Topic 

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2008-11-24 : 07:29:10
Hi, I need help please.

I need to test if a certain id is in a table, if it is I want to return 1 row with value = 'Yes' else 'No'
But i'm struggling to da a case on no results returned:

select case when Role.Description = '' then 'No' else 'Yes' end as Description
from dbo.fcUserGroup UserID
left join dbo.fcRoleGroup Role
on UserID.RoleGroupID = Role.ID
where Role.Name = 'RD NFG' and UserID.RoleID = 69

Regards

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 07:32:36
do you mean this?
SELECT case when(select count(*) from dbo.fcUserGroup UserID 
left join dbo.fcRoleGroup Role
on UserID.RoleGroupID = Role.ID
where Role.Name = 'RD NFG' and UserID.RoleID = 69)
=0 then 'No' else 'Yes' end as Description

Go to Top of Page

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2008-11-24 : 08:02:47
Thank You - this is great!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 08:39:39
Welcome
Go to Top of Page
   

- Advertisement -