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 2008 Forums
 Transact-SQL (2008)
 is it possible to "if not in T1, look in T2?

Author  Topic 

janwane
Starting Member

9 Posts

Posted - 2012-05-31 : 13:25:24
I've taken over maintenance of someone else's app and was given a modification task but I can't get a clear grasp of how to approach the solution. This is the existing query:

select p.*, (select case when count(*) > 0 then 'Y' else 'N' end as SL from tbl_fedlog where [Part Number] = p.[Part Number]) as SL
from tbl_pcms p where p.[Tech Order] = @TechOrder
order by p.Figure, p.[Index], p.Indenture

To put this in English, there are Tech Orders (tbl_pcms) that tell you how to maintain an airplane. They contain part numbers. The above query looks in the Fedlog table (a table from a gov't legacy system). Boss wants mod so if not found in Fedlog table, look in "Commercial" table. The result must be a single data source for a .Net gridview. I'm playing around with Union queries but not making much headway. Anybody have solution? Advice? Thanks!

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-05-31 : 13:30:10
[code]SELECT p.*,
CASE WHEN EXISTS(SELECT * FROM tbl_fedlog WHERE [Part Number] = p.[Part Number])
OR EXISTS(SELECT * FROM Commercial WHERE [Part Number] = p.[Part Number])
THEN 'Y' ELSE 'N' END AS SL
FROM tbl_pcms p WHERE p.[Tech ORDER] = @TechOrder
ORDER BY p.Figure, p.[Index], p.Indenture[/code]
Go to Top of Page

janwane
Starting Member

9 Posts

Posted - 2012-05-31 : 16:05:27
Thanks robvolk!
Go to Top of Page
   

- Advertisement -