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 |
MikeB
Constraint Violating Yak Guru
387 Posts |
Posted - 2005-02-23 : 15:14:57
|
I need to get all fkAccountID, fkCostTypeID entries from table 1 where the fkAccountID falls in the account category (fkAccountCategoryID - Table 3) as indicated by the EntryID in table 1tbAccountCostTypes (table 1)EntryID | fkAccountID | fkCostTypeID | Code-------------------------------------------1 | 1 | 21 | E12 | 1 | 22 | F13 | 2 | 21 | E14 | 3 | 45 | 10tbAccounts (table 2)AccountID | fkAccountCategoryID | Descr---------------------------------------1 | 1 | BLAH2 | 1 | BLAH BLAH3 | 2 | BLAHtbAccountCategories (table 3)AccountCategoryID | Descr --------------------------1 | BLAH 2 | BLAH By passing in Entry 1, I should get back only row 1 and 3 from tbAccountCostTypes (Table 1)They derive from the same account category and have = cost type id'sAny help ?Mike B |
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-02-23 : 15:26:18
|
I'm not sure what all three tables are there for..Declare @entryId intSet @entryId = 1Select *From tbAccountCostTypes Where fkCostTypeID = (Select fkCostTypeID from tbAccountCostTypes where entryId = @entryId) Corey"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain |
|
|
MikeB
Constraint Violating Yak Guru
387 Posts |
Posted - 2005-02-23 : 15:33:39
|
quote: Originally posted by Seventhnight I'm not sure what all three tables are there for..Declare @entryId intSet @entryId = 1Select *From tbAccountCostTypes Where fkCostTypeID = (Select fkCostTypeID from tbAccountCostTypes where entryId = @entryId) Corey"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Thanks, but the cost type could be associated with accounts that fall into multiple account categories. The account must fall within the category associated the original account that is associated to the entryID.This is the reason for all three tables. Mike B |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2005-02-23 : 16:35:29
|
Mike,Post the DDL for the tables and table relations and the DML for populating them, it'll make it easier for the community to answer your question.JonathanGaming will never be the same |
|
|
|
|
|