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.
Author |
Topic |
Hoss
Starting Member
2 Posts |
Posted - 2005-05-13 : 06:24:01
|
HiI have a problem that Im pretty sure will have an easy fix but Im pretty new to this stuff:I have a query that returns multiple rows based on criteria. e.g.SELECT id, name, address FROM table1 Where name LIKE '%SMITH'I want to add another column to the returned recordset that is a boolean (found/not found) depending upon whether the id returned exists in table 2. (the selection criteria isn't whether it exists in both as I have to return all the values whether it exists in the second table or not.)Could anyone point me in the right direction for doing this pleasethanks |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2005-05-13 : 07:07:33
|
something nice and ugly like this maybe?SELECT a.id, a.name, a.address, case (COALESCE(cast(b.id as varchar(5)), 'FALSE')) when 'FALSE' then 'FALSE' else 'TRUE' end as [My cool exists or not column]FROM table1 aleft JOIN table2 b on a.id = b.idWHERE a.name LIKE '%SMITH'EDIT: gave the column a name |
 |
|
Hoss
Starting Member
2 Posts |
Posted - 2005-05-13 : 08:23:10
|
Thanks Don ... works a treat |
 |
|
|
|
|