Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with Query
Message
From
10/11/2006 07:53:04
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Miscellaneous
Thread ID:
01168699
Message ID:
01168702
Views:
8
>Hello All, I need to include a derived field in a view based on whether a certain value is present in another table ( does that make sense ? ). The problem is, the table in question can have more than one record but I'm only interested in a certain type, any ideas as to how I can do this ?
>
>pseudo code
>
>Select * from table1 and if there is a record of type 'X' in table2 set field2 to 1 else set field2 to 0
SELECT DISTINCT Table1.*,
       CASE WHEN Table2.Type IS NULL THEN 0 ELSE 1 END AS Tbl2Type
FROM Table1
LEFT JOIN Table2 ON Table1.PK = Table2.FK AND Table2.Type = 'X'
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform