Solved

Best Practice SQL. Is it possible to make this a view?

Posted on 2008-10-21
2
128 Views
Last Modified: 2012-05-05
I might be totally off here but I'm trying to avoid pointing to a specific row in the AccountGroup table. I want to be able to change the names of the groups but the Account Numbers has built in meanings according to standard chart of accounts in Europe.

AccountGroup contains AccountGroupNos like:
No: 1
Descr: 'Assets'
No: 11
Descr: 'My Machinery Assets of type 1'

Account contains the accountnos:

No: 1110
Descr: My Machine type 1
No: 1111
Desc: My Machine type 2

Now, is this good practice or should I in fact store the AccountGroupID in the Account based on the formula below each time I add an Account? Or if this is OK, is it possible to do the query without the #temp-table so I can put the code in a view?

I don't know if it makes a difference but the database is located in a .MDF SQL Express file and will run localy on the end users computer.

Tanks in advance!

/Tomas


SELECT a.AccountID, a.Accountno, a.AccountDescription, g.AccountGroupDescription 
INTO #TEMP
FROM Account a, AccountGroup g
WHERE left(a.accountno,2) = g.AccountGroupNo
SELECT AccountID, AccountNo, AccountDescription, a.AccountGroupDescription, g.AccountGroupDescription as MainAccountGroup
FROM #temp a, AccountGroup g
WHERE left(a.accountno,1) = g.AccountGroupNo
ORDER BY AccountNo

Open in new window

0
Comment
Question by:ekenman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:ekenman
ID: 22765965
OK, I managed to get the question a little bit more accurate. The question remaining is if it is OK to do this? Is it good practice?
SELECT     MG.AccountGroupNo as MainGroupNo, MG.AccountGroupDescription as MainAccountGroupDescription, G.AccountGroupNo, G.AccountGroupDescription, Account.AccountNo, Account.AccountDescription
FROM         Account INNER JOIN
                      AccountGroup as G ON LEFT(Account.AccountNo, 2) = G.AccountGroupNo INNER JOIN
					  AccountGroup as MG ON LEFT(Account.AccountNo,1) = MG.AccountGroupNo 

Open in new window

0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 250 total points
ID: 22772424
Based upon your query above in http:#22765965, the AccountGroupNo should be in the Account table.  It also seems, since you have two joins to accountgroup, that an account is part of two groups.  once based upon the first and once based upon the second.  Perhaps this is a good candidate for group and subgroup.
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question