Parent/Child dataset select

M

Midtown2oo3

Parent table
--------------------
Key
Count
Name
Type

Child table
--------------------
Key
ParentKey
Account
Department

"ParentKey" is a foreign key between the two tables.

I would like to perform a select as such: ChildTable.Select
([Department] = 'Dept1' AND Parent.[Type] = 'Public')

Is this even a possibility?

Thanks in advance.
 
N

Nathan Sokalski

First of all, what do you want the result to be? Second, it sounds like you
should be looking at a newsgroup for SQL, possibly one of the
microsoft.public.sqlserver newsgroups.
 
G

Gregory A. Beamer

Child table
--------------------
Key
ParentKey
Account
Department

"ParentKey" is a foreign key between the two tables.

I would like to perform a select as such: ChildTable.Select
([Department] = 'Dept1' AND Parent.[Type] = 'Public')

Is this even a possibility?


From a SQL standpoint? Very easy:

SELECT Child.*
FROM Child c
JOIN Parent p
ON c.ParentKey = p.Key
WHERE c.Department = @Dept
AND p.Type = @Type

From a DataSet, Entity or LINQ to SQL. Also easy enough, once you have
the model with both items. It still follows the basic idea shown in the
SQL query above.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top