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
 Old Forums
 CLOSED - General SQL Server
 Select statement help.

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 1


tbAccountCostTypes (table 1)
EntryID | fkAccountID | fkCostTypeID | Code
-------------------------------------------
1 | 1 | 21 | E1
2 | 1 | 22 | F1
3 | 2 | 21 | E1
4 | 3 | 45 | 10

tbAccounts (table 2)
AccountID | fkAccountCategoryID | Descr
---------------------------------------
1 | 1 | BLAH
2 | 1 | BLAH BLAH
3 | 2 | BLAH

tbAccountCategories (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's

Any 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 int
Set @entryId = 1

Select *
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
Go to Top of Page

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 int
Set @entryId = 1

Select *
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
Go to Top of Page

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.

Jonathan
Gaming will never be the same
Go to Top of Page
   

- Advertisement -