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
 General SQL Server Forums
 New to SQL Server Programming
 How to get a Boolean result?

Author  Topic 

scantoria
Starting Member

15 Posts

Posted - 2009-11-20 : 17:21:42
I have a record and attachment tables. I need to write a query that will let me know if there is a file attached to a record. would be nice if I can get the result in boolean data type.

Stephen Cantoria
scantoria@msn.com

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-20 : 17:44:56
ummmmm

SELECT r.key, 1 AS Nonesense
FROM Records r
LEFT JOIN Attachments a
WHERE r.key = a.key
WHERE a .key IS NULL

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-11-20 : 17:46:59
[code]SELECT Case WHEN Exists(SELECT * FROM t1 JOIN j2 on t1.id = t2.id) THEN 1 ELSE 0 END[/code]
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-20 : 18:01:36
quote:
Originally posted by russell

SELECT Case WHEN Exists(SELECT * FROM t1 JOIN j2 on t1.id = t2.id) THEN 1 ELSE 0 END




mmmmmm.....blotter



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

scantoria
Starting Member

15 Posts

Posted - 2009-11-20 : 18:36:35
quote:
Originally posted by russell

SELECT Case WHEN Exists(SELECT * FROM t1 JOIN j2 on t1.id = t2.id) THEN 1 ELSE 0 END




Thank you so much. This query did the trick.

Stephen Cantoria
scantoria@msn.com
Go to Top of Page
   

- Advertisement -