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)
 retuen yes or no by querying result.

Author  Topic 

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2008-08-07 : 13:59:12
Hello,

I want to return "Y" or "N" according to the query result.

where exist(select a from tablename where id='xxx')

If it is true, return "Y". Otherwise "N".

Can you please give me a hint?

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-07 : 14:03:49
[code]select case when t1.a is null then 'N' else 'Y' end
from yourtable t
left join tablename t1
on t1.id=t.id
where t.id='xxx'[/code]
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-08-07 : 14:04:00
[code]
select
coalesce((select distinct 'Y'from tablename where id='xxx'),'N') as Returned
[/code]
Go to Top of Page
   

- Advertisement -