SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Select statement help.
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

MikeB
Constraint Violating Yak Guru

Canada
387 Posts

Posted - 02/23/2005 :  15:14:57  Show Profile
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
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 02/23/2005 :  15:26:18  Show Profile  Visit Seventhnight's Homepage
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

Canada
387 Posts

Posted - 02/23/2005 :  15:33:39  Show Profile
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

USA
992 Posts

Posted - 02/23/2005 :  16:35:29  Show Profile
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
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000